Looper Query String

Hi there,

I am looking to remove the need for ‘The Grid’ plugin to show my WooCommerce products.

I currently have The Grid set-up to show products using the following Meta Key filter…

This works as expected. Now, using Loopers, I am creating a query string with the following information to achieve the same result…

post_type=product&_lottery_closed=-2&_lottery_started=-0

However, it’s not working as expected. Am I missing something here and is this even possible within the Loopers query string functionality?

Thanks in advance!

Hello @kademcconville,

Thanks for writing to us.

In case if you want to display filtered product by meta key you need to meta query. Please have look at this thread to learn more about how to write meta queries in the query strings.

Hope it helps
Thanks

Hi there,

Thanks for that reference…

I have tried

post_type=product&meta_key=_lottery_started&meta_value=-0&meta_key=_lottery_closed&meta_value=-2

But no results are coming through. Just matching the query found on the grid.

The reference also shows just 1 meta field, not 2 as per this case which may complicate the matter.

Thanks!

Hello @kademcconville,

Please check out first @Kory’s reply on this thread:

And then you will have to write out a query using the standard WP_Query syntax like:

$query = array(
    'post_type'  => 'product',
    'meta_query' => array(
        'relation' => 'AND',
        array(
            'key'     => '_lottery_started',
            'value'   => '-0',
            'compare' => 'NOT EXISTS',
        ),
        array(
            'key'     => '_lottery_closed',
            'value'   => '-2',
            'compare' => 'NOT EXISTS',
        ),
    ),
);

Then, check the output that somehow utilizing http_build_query() , which will format our string accordingly:

var_dump( http_build_query( $query ) );

You may get something like this for the query string: post_type=product&meta_query%5Brelation%5D=AND&meta_query%5B0%5D%5Bkey%5D=_lottery_started&meta_query%5B0%5D%5Bvalue%5D=-0&meta_query%5B0%5D%5Bcompare%5D=NOT+EXISTS&meta_query%5B1%5D%5Bkey%5D=_lottery_closed&meta_query%5B1%5D%5Bvalue%5D=-2&meta_query%5B1%5D%5Bcompare%5D=NOT+EXISTS

Hope this helps.

Thanks for the help. Looking into the thread I run a query.

Interestingly, I get 2 different outputs from the provider:

12 Products - “post_type=product&product_cat=Active&posts_per_page=-1&orderby=_dates_to&order=asc”

11 Products - post_type=product&product_cat=Active&posts_per_page=-1&orderby=_dates_to&order=asc

I.e. the " at the beginning and end make a different output of data. Would this appear correct or a bug?

Cheers.

Hi @kademcconville,

I have checked the similar Query String but it returns the same number of products every time it is executed. It will be very difficult to recognize the problem without investigating your website.
Can you please share the website URL and the login credentials for your site in a secure note to examine it, including:

– WordPress Site URL & Login URL
– Any specific page where you are having this issue.
– WordPress Admin username/password

To create a secure note, click the key icon underneath any of your posts.

Thanks

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.