lewisR
Support threads created in the last 30 days: 0
Favorite Forum Topics
This user has no favorite topics.
Forum Topics Created
Status | Topic | Supporter | Voices | Posts | Freshness |
---|---|---|---|---|---|
WPML notice in Toolset installer
Started by: lewisR in: Toolset Professional Support |
2 | 5 | 3 years, 8 months ago | ||
Custom field code is not working on "Posts Page"
Started by: lewisR in: Toolset Professional Support |
3 | 5 | 4 years ago | ||
Post field group with repeatable group doesn't display in designated template
Started by: lewisR in: Toolset Professional Support |
2 | 4 | 4 years, 5 months ago | ||
Blank default option in pre-populated select field
Started by: lewisR in: Toolset Professional Support |
2 | 3 | 4 years, 5 months ago | ||
Split: Blank default option in pre-populated select field – how to change/reove "Enter your internal title for the item" for repeatable group field
Started by: lewisR in: Toolset Professional Support |
2 | 2 | 4 years, 5 months ago | ||
Query posts using post IDs stored in custom fields in a Repeatable Field Group
Started by: lewisR
in: Toolset Professional Support
Problem: I have a Repeatable Field Group (RFG) that contains a custom field holding a post ID. I would like to use PHP to get all the RFGs associated with the current posts, then loop over and display the posts in this array in the same order as the corresponding RFGs are sorted in wp-admin. Solution: Initialize an empty array, which will be used to hold a list of post IDs. Use the toolset_get_related_posts API to query for RFGs as child posts of the current post. Use orderby => rfg_order to sort the RFG results using the visual order applied in wp-admin. Loop over the results using foreach, get the value of the post ID custom field using types_render_field or get_post_meta, and push that value onto the empty array. Call the query_posts WordPress API and provide the array of post IDs in the post__in argument. Use orderby => post__in to preserve the sorted order of the post__in array. Example: $insert_ids = []; // empty array initialization $child_posts = toolset_get_related_posts( get_the_ID(), 'mdsc-post-ads', array( 'query_by_role' => 'parent', 'return' => 'post_object', 'orderby' => 'rfg_order' ) ); foreach ($child_posts as $child_post) { $insert_ids[] = types_render_field( "mdsc-select-ads", array( "id"=> "$child_post->ID", "output" => "raw" )); // push each field value on to the array } query_posts( array ( 'post_type' => 'mdsc-ads', 'posts_per_page' => -1, 'post__in' => $insert_ids, // query the array of post IDs directly 'orderby' => 'post__in', )); Then loop over those results using a standard loop: while ( have_posts()) : the_post(); // ... the loop endwhile; wp_reset_query(); Relevant Documentation: |
2 | 8 | 4 years, 5 months ago |