Repeater fields for Pods Framework. Adding a repeatable field on pages.
Panda Pods Repeater Field is a plugin for Pods Framework. The beauty of it is that it is not just a repeater field. It is a quick way to set up a relational database and present the data on the same page. It takes the advantage of Pods table storage, so you don’t need to worry that the posts and postmeta data table may expand dramatically and slow down page loading. This plugin is compatible with Pods Framework 2.8 or later. To download Pods Framework, please visit http://pods.io/. After each update, please clear the cache to make sure the CSS and JS are updated. Usually, Ctrl + F5 will do the trick.
/wp-content/plugins/panda-pods-repeater-field
directory, or install the plugin through the WordPress plugins screen directly.After the activation of Pods Framework, please also activate Advance Content Type and Table Storage in Pods Admin, under the Components section.
Activate Advance Content Type.
Activate Table Storage.
Here, you will learn how to use it through an example. First, we have to add a new Pod. In Pods, please click Create New.
and create a new Pod with Advance Content Type. In this tutorial, we call it "Comic Content"
We are going to use Comic Content as the storage of a repeater field.
Under the Admin UI tab, untick Show Admin Menu in Dashboard, because if you add an item to it, it is not linked to any parent posts.
Now we create a new post type in Pod. We name it "Comic" and we use Table Based storage, because we want to reduce the burden of the WordPress Posts table.
Once it has been created, we add a new field to Comic. We name it "Comic Box 1" here. At the bottom of the Field Type, you will find Pods Table As Repeater Field. Select it and then click the tab "Additional Field Options".
Now you can see a Pods Table "comic_content" we just created in the combo box. Select it, add or update the field and save Pod. You can set field width, defaulted to 100%. You can also limit the number of entries of the repeater field. Enable Trash will allow you to move items to Trash and Restore them if you still want them. Trashed items won't be pulled out by pods_field() and pandarf_items_fn(), but if you diable Trash later on, the trashed items will still be pulled out. There are other advanced options to choose. They should be self-explanatory.
If you are doing nested repeater fields, I recommend you set it to 100%. A sample of nested repeater fields.
OK, the set up is done. Now if you are adding a new Comic,
you will see "Comic Box 1" in the More Fields area.
You can add as many new items to Comic Box 1 as you want, and they are only attached to the current Comic you are editing .
You can click top bar to contract it, the bottom bar to expand the window.
To find the parent_pod_id and parent_pod_field_id, go to Pods and click the main Pod (Comics in this tutorial).
Here, 2215 is parent_pod_id and 2222 is parent_pod_field_id
To find the parent_pod_post_id, open the main post and look at the URL. If you are using a Pods Adavnce Custom Type or a Custom Post Type as the main table, it is the "id" variable in the URL. If you add a repeater field to Settings, the parent post id is the same as parent_pod_id. If you add a repeater field to Users, the parent post id is the same as the user ID.
The Load More functionality settings.
Instructions for the Load More functionality.
The Order option settings.
Display Order Info.
Please see the screenshots for instructions.
From Version 1.1.4, you can use pods_field(). e.g. in a single post template, pods_field( ‘field_name’ ) to fetch the data for the current page, otherwise use pods_field( ‘pods_name’, ‘post_id’, ‘field_name’ ) to fetch any data you want anywhere. To fetch data from the settings area, use pods_field( ‘pods_name’, false, ‘field_name’ ). To fetch data from the users area, use pods_field( ‘user’, ‘user_id’, ‘field_name’ ).
You can use the filters: pandarf_pods_field_attrs( array(), $value_ukn, $row_arr, $params_arr, $pods_obj ) and pandarf_data_attrs( array(), $data_arr, $parent_pod_name ) to alter the repeater data returned from pods_field().
From Version 1.1.6, if the field type is “file”, it will return the file ids, then use WordPress APIs like get_attached_file(), wp_get_attachment_image_src() etc to get the file details. Relation types of ‘user’, ‘post type’, ‘pod’ and ‘media’ will now return the saved ID.
You can also use this API to fetch data: pandarf_items_fn( $fields_arr, $attrs, $show_query ). Please see the Screenshots section for how to find ids.
$fields_arr search repeater field table
array(
‘id’ => ”, // row id
‘name’ => ”, // the common name field used by pods
‘child_pod_name’ => ”, // repeater table name
‘parent_pod_id’ => ”,// main table pod id
‘parent_pod_post_id’ => ”, // main table post id
‘parent_pod_field_id’ => ”, // main table pod Panda Pod Repeater Field id
)
$attrs for some basic mySQL commands (Optional)
array(
‘where’ => ”, // exter where, expected to be escaped
‘order’ => ‘ASC’,
‘order_by’ => ‘pandarf_order’,
‘group_by’ => ”,
‘start’ => 0,
‘limit’ => 0,
‘count_only’ => false, // if true, it will return the amount of rows in an array.
‘add_tb_prefix’ => true, // add $table_prefix to the table name. Default to ture
)
$show_query
If set to true, it will print out the sql command. For debugging purpose. Default to false.
An example of basic usage. IDs from the Screenshots section:
get_pandarf_items( array( ‘child_pod_name’ => ‘comic_item’, ‘parent_pod_id’ => 2273, ‘parent_pod_post_id’ => 2275, ‘parent_pod_field_id’ => 2274 ) );
or pandarf_items_fn before v1.4.11
It will return the items attached to the post from Comic Contents.
You can use this API to insert data: pandarf_insert( $fields_arr, $prf_arr, $show_query ). Please see the screenshots for how to find ids.
$fields_arr extra fields other than panda repeater fields to insert:
array(
‘field_name’ => ”,
‘field_name’ => ”
… …
)
$prf_arr the default repeater fields
array(
‘child_pod_name’ => ”, // The name of the table for saving repeater field items.
‘parent_pod_id’ => ”, // main table pod id
‘parent_pod_post_id’ => ”, // main table post id
‘parent_pod_field_id’ => ”, // main table Panda Pods Pod Repeater Field id
‘user_id’ => 0 // The author id
‘add_tb_prefix’ => true, // add $table_prefix to the table name. Default to ture
)
$show_query
If set to true, it will print out the sql command. For debugging purpose. Default to false.
This API will return the wpdb inserted ID if successful, or false on failure.
An example of basic usage. IDs from the Screenshots section:
$id_int = pandarf_insert( array( ‘name’ => “hello panda” ), array( ‘child_pod_name’ => ‘comic_item’, ‘parent_pod_id’ => 2273, ‘parent_pod_post_id’ => 2275, ‘parent_pod_field_id’ => 2274, ‘user_id’ => $current_user->ID ) );
/**
* The repeater field is only for logged in users with edit_posts capability
* If you want it to be available for the frontend users, you can use this filter
*
* @param boolean $is_allowed allow the form to be displayed
* @param array $get_arr variables from $_GET
* @return boolean still allow or not
*/
function pprf_allow( $is_allowed, $get_arr ){
$pod_obj = pods('your_pod_slug'); if( $get_arr['podid'] == $pod_obj->pod_id ){ $is_allowed = true; } return $is_allowed;
}
Add this code to your functions.php
add_action( ‘wp_enqueue_scripts’, ‘dequeue_scripts_and_styles’, 11 );
function dequeue_scripts_and_styles() {
wp_dequeue_script( ‘panda-pods-repeater-scripts’ );
wp_dequeue_style( ‘panda-pods-repeater-general-styles’ );
wp_dequeue_style( ‘panda-pods-repeater-styles’ );
}