Download the PHP package tacowordpress2/addmany without Composer

On this page you can find all versions of the php package tacowordpress2/addmany. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package addmany

AddMany:

In simplest terms allows relationships between posts. The visual interface gives WordPress admin the ability to assign one-to-many relationships with children that share no other parents. You can also allow many-to-many relationships where children may have many parents and vice versa. You can even create shared fields between parent and children which is important for things like products that may change price at different store locations. More on that later.

Similar to ACF (Advanced Custom Fields), AddMany has the ability to create and repeat sets of fields. The main difference being, it puts control back into the hands of the developer and allows you to write custom MySQL queries if need be.

*Requires WordPress 4.8 and later.

Table of Contents

Use Cases

How it Works

Related Posts

What happens behind the scenes

Why is there a "Subpost" between my current post and the related post? What is a SubPost?

It would probably be helpful to explain what a "SubPost" is. It is a custom post type that sits between the post and the related post. It's hidden from the WordPress admin menus but you're actually seeing as a row whenever you add a related post in the UI.

There are a number of important reasons why AddMany uses a SubPost:

Requirements

AddMany would not be possible without The TacoWordPress framework – An ORM for custom post types. This is a requirement.

Other requirements:
Built with React and PHP

Installation

Depending on where you put your project's vendor directory, installation may or may not work. A solution is currently being worked on to resolve this.

In your project's composer.json file, add the packages below in the require section:

Run composer update or composer install in the terminal.

In your theme's function file, add the below:

Example Usage

With the examples below, you should have prior knowledge of how TacoWordPress works. If not, please consult the docs here: https://github.com/tacowordpress/tacowordpress/wiki.

One-to-Many

Many-to-Many (AddBySearch)

Many-to-Many with unique common fields between 2 posts (like a junction table)

In this example, the shared fields are between the parent post and the child posts of "products".

Because the above will reference external "product" posts, you have the ability to extend their values ("price" and "tax" is a good use case) while also keeping their original values. This is useful for creating products and allowing them to slightly vary between stores.

One-to-Many with field variations

Field variations allow the admin user to select and add a combination of different field groups. This allows for more customization of layouts. An example might be a sidebar that has many different modules. Each module would have a different set of fields that control the content, look, and feel. Another example (featured below) might be a staff page with a grid of photos and information for each person. Instead of the layout being separated by staff member type, they are mixed together. You could create 1 field group with all the fields necessary to satifsy both staff member types, but that might cause some field bloat. With fields variations, you can create one field group for board members and another for general staff while keeping them together in the same grid.

One-to-One

Getting a post's relations

In your template you can get related posts by accessing the field name through your object, e.g. This will return a collection of post objects.

In order to utilize the above, you must use the AddMany Mixin within your class.

This will let you do the following:

What if no related posts exist in the object?

In other words, the admin did not manually select them. You can define a fallback method. This will alow for cleaner code in your template by removing any logic.

This example shows a method that is defined in the Post class:

Ordering - What if I just want that?

You can do that too!

Specifing ordering by "uses_ordering => true" removes the ability to search posts and instead adds all records for that post type. This gives the admin user the ability to order by drag and drop. Be careful though, AddMany will create a new subpost for published posts in the the database (of that post type). In some cases your better off using this feature to order smaller subsets of data. See the "Customizing how search results get returned in the UI" for how.

IMPORTANT: The method you define must be named "getFallBackRelatedPosts". It can handle more than one field if you allow it. Just create a switch statement or some logic to check the key and then return the appropriate posts.

Getting original values of a referenced post if overwritten

With AddMany you can override values from a post that you reference through AddBySearch. This is extremely useful if you have a template (of some sort) or even a product that may need its values replaced without having to recreate it.

Let's say there are a chain of stores that all carry the same product/s but the prices vary from location to location. The following code will allow this:

The admin interface will give you the ability to find and add the products to a list. This list will contain the products with an additional field of "price". Typing a value in these fields will override it but not replace the original.

To understand this concept better, let's create the template code that displays some basic product information.

By accessing the property of "original_fields", you will get the original value while keeping the new value. $product->original_fields->price;

This is also useful to show product savings after a reduction in price.

Customizing how search results get returned in the UI

If you're using the AddMany's AddbySearch functionality to query and assign related posts, there is a chance you need to narrow the results even further. Let's say you wanted to return posts of the custom post type person that have a term of "employee" but there are hundreds of people to pick from. You can create your own method to make the results more definitive. By default, the AddMany core method looks like this:

Creating your own method

We will use the example above where the UI needs to return posts of the custom post type person with a term of "employee" of the taxonony (slug) "person-type".

Note: It's important to keep the text querying ("s" property) in the WP_Query so the user admin can still search with keywords. Also, when returning an array, the key is required to be the post ID and value "should" be the post title but that isn't totally necessary.

Next we need assign this method in "getFields()".

In the above code "Person" is the post type class name and "getEmployees" is the new method we just created above.

UI - Defining what shows when rows are collapsed

Reordering via drag and drop can be cumbersome when the height of rows grow and takes up most of the screen. A collapse button has been provided to decrease the height of these items. This creates an issue of what to show when the height of rows are shortened. By default, AddMany shows a collection of truncated field values from a row to give the admin user an easier task of identifying which is which. You can also specify via code which field value shows, by adding the field name for the key of "show_on_collapsed" in the options part of the array.

Here's an example how.

Convenience methods

The Factory class of AddMany has a few convenience methods to make your code just a little cleaner:

Basic AddMany \Taco\AddMany\createAndGet() will return the array without having to call ->toArray()

AddMany with AddBySearch

\Taco\AddMany\createAndGetWithAddBySearch() will also return an array

Contributing (Coming soon)

Changelog

v0.2.4

v0.2.3

v0.2.2

v0.2.1

v0.2

v0.1


All versions of addmany with dependencies

PHP Build Version
Package Version
Requires php Version >= 5.4
tacowordpress2/frontend-loader Version ^1.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package tacowordpress2/addmany contains the following files

Loading the files please wait ....