Evening all – long time ACF user who has given up searching and hopes someone can help him!
We have Manufacturers (Custom Post Type)
We have Products (Custom Post Type)
When you add a Product, you select the name of the Manufacturer from a drop down list, populated from the Manufacturers CPT list. So far, so good.
I want to run a query on a Manufacturer specific page, show all Product connected to this Manufacturer.
This query (below) works – but only because I am specifying the meta_value.
207 is the Post Object which matches the manufacturers name (field name ‘product_manufacturer’). And the page the query is running on is titled the same.
So, I want some way – by creating a variable perhaps? – to ‘look up’ the ID (and get 207) knowing that the_title matches ‘product_manufacturer’.
This gives me a variable based on the page title
<?php $pagemanuf = get_the_title(); ?>
But if I replace 207 below with $pagemanuf everything goes belly up.
I know this is simple, and I know I’ll kick myself when someone tells me what I’ve done wrong!
<?php $args = array(
‘meta_key’ => ‘product_manufacturer’,
‘meta_value’ => ‘207’
while ($manufprods->have_posts()) : $manufprods->the_post();?>
<?php get_template_part(‘inc/productloop’); ?>
<?php endwhile; wp_reset_postdata();?>
Thanks in anticipation, and an offer of beer if the lucky helper is close to Manchester, UK!
John, you’re a star. I knew it would be something stupidly obvious. My brain had obviously decided to go on a short holiday yesterday.
I’m guessing (often dangerous), that you’re not in close vicinity to Manchester – but should you ever find yourself in this neck of the woods, let me know and I’ll be buying you a pint of something cold and refreshing.
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
© 2022 Advanced Custom Fields.