Support

Account

Home Forums General Issues Want Page ID in post_id Field Reply To: Want Page ID in post_id Field

  • Hi!

    Your logic is a bit backwards but it’ll still work.. So what you want is to display the products which are “connected” to a page being viewed.. unfortunately there’s no way to do this query on just those four pages (unless they use a custom template file) but you can do something like this on the page template:

    
    <?php
    $args = array(
    'post_type' => 'products',
    'posts_per_page' => -1,
    'meta_query' => array(
    		array(
    			'key' => 'make_partner_featured',
    			'value' => "$post->ID",
    			'compare' => '='
    		)
    	)
    );
    $products = new WP_Query($args);
    if($products->have_posts()): while($products->have_posts()): $products->the_post();
    
    //Show title
    the_title();
    
    endwhile; wp_reset_postdata(); endif;
    ?>
    

    Put this is your page template file and it’ll query your products when visiting a page and if the products ACF field value corresponds to the current pages id they will be fetched and the title of the product will be output.

    It’d be better to just do this when you know you’re on one of the pages in question and not all pages.. you can solve this by either giving them a custom page template or by a simple if statement around the code checking the current pages id against the four ids you have.. The second solution isn’t dynamic tho since you’d have to add another pages id in the if-statement if you want it to have the same feature..