Query String Filter

Hey Folks,
I’ve been trying to avoid reaching out but I’m getting myself turned around.

I have a Single Layout with a looper. The general idea is that when I select a Designer (link on another page with designer name passed in the URL), I should land on this page and see all of the home designs they’ve created.

Here’s the page: https://vermontframstg.wpenginepowered.com/designer/classic-timberworks-designs/

This layout for it is called Designers Layout.

The current Query String is: post_type=timber_frame_design&posts_per_page=25

I can’t seem to find the right combination to get the filter to work. In this case the page should only show the designs where designer_name is Classic Timberworks Designs

Hi Gregg,

Thanks for reaching out.
You need to use the Meta Query to provide the specific Meta Field for Designer Name and the value to be compared, as explained in the following threads. And one of those that I already suggested to you.


After you create the array of arguments of the Query and then just use the http_build_query function to format it into Query String, as explained in the following thread.


Hope it helps.
Thanks

Hey @tristup,
Thanks for the reply. Yes, I have been referencing the posts you shared but I’m missing something or just not getting the syntax correct. Here’s the test PHP I used:

$designer[] = array(
‘meta_key’ => ‘who_designed_it’,
‘operator’ => ‘=’,
‘meta_value’ => ‘{{dc:post:title}}’,
);

$query = array(
‘post_type’ => ‘timber_frame_design’,
‘posts_per_page’ => 25,
‘designer_name’ => $designer,
);

var_dump( http_build_query( $query ) );

Which yields: post_type=timber_frame_design&posts_per_page=25&designer_name%5B0%5D%5Bmeta_key%5D=who_designed_it&designer_name%5B0%5D%5Boperator%5D=%3D&designer_name%5B0%5D%5Bmeta_value%5D=%7B%7Bdc%3Apost%3Atitle%7D%7D

Hi Gregg,

You can follow the way the Meta Query is written in the following thread, and change the Meta Key and the value to be compared, i.e., ACF field value {{dc:acf:post_field field="field_name"}}. Please remember that the {{dc:post:title}} always returns the current Post Title, not the Designer Name, which is stored as Meta Value.

Your Query String should look like the following one.

$query = array(
    'post_type'           => 'timber_frame_design',
    'orderby'             => 'meta_value',
    'meta_key' 			  => 'who_designed_it',
    'meta_query' => array(
        array(
            'key'		=> 'who_designed_it',
            'compare'	=> '=',
            'value'		=> {{dc:acf:post_field field="field_name"}},
        )
    ),
    'order'               => 'asc'
);

Please remember that the above code will work if copied as it is and doesn’t conflict with any existing style.
Please note that the code provided serves only as a guide to help you get started with custom coding on your own if there’s no option offered in our theme or the products we bundle.
We really do not provide support for custom codes, which means we can’t fix it in case it conflicts with something on your site, nor will we enhance it. Further customization should be directed to a third-party developer, or you can avail yourself of One, where we answer the questions beyond normal theme support.

Thanks

Hi @tristup,
Understood. Thank you for the help and info.

Gregg

You are most welcome, Gregg.