• Resolved hillvalleytech

    (@hillvalleytech)


    I have 2 custom post types: “Menu Items” and “Restaurants”. Within the Types plugin admin I set “Menu Items” to be a child of “Restaurants”. I have several “Menu Items” now attached to their respective “Restaurant”.

    I’m using the WP_query loop to display my “Menu Items” in a list with the fields I’ve chosen and that is working fine. Here’s the beginning of that that looks like:

    $args = array('post_type' => 'menu-items', 'meta_key' => 'wpcf-order', orderby => 'meta_value_num', order => 'ASC');
          $query = new WP_Query($args);
          while($query -> have_posts()) : $query -> the_post();
          $htmlTag = types_render_field( "html", array( 'raw' => true) ); echo $htmlTag;
    echo the_title(); $content = $post->post_content; echo $content;

    etc

    Now I want to filter this further to only display “Menu Items” that are a child of a certain “Restaurant” that I specify. Either by slug, or ID. I’m confused on how to do this with types_child_posts.

    I know I can use post__in in the $args but I don’t know how to get the list of children post id’s into an indexed array.

    https://www.ads-software.com/plugins/types/

Viewing 1 replies (of 1 total)
  • Thread Starter hillvalleytech

    (@hillvalleytech)

    Actually I decided to go about it a different way. Instead of using the “Types” child/parent option, I added a new custom field to my Menu Items CPT called Restaurant ID. I’ll then put the “parent” restaurant’s ID in the “child” Menu Items Restaurant ID field and use that to filter my queries. Since I’m going to be adding most content through CSV imports this won’t require any extra tedious work of having to fill out the ID for each item.

Viewing 1 replies (of 1 total)
  • The topic ‘Want display only children of a certain parent that I specify in loop’ is closed to new replies.