Query String Looper Provider Question

Have a Looper provider that uses meta_compare=LIKE in the query string. Compares the post id and works great, except it will match related posts that have the same post id value somewhere in them.

Example it thinks 149 and 25149 are the same. Is there something other than LIKE I should be using/adding?

Hi @xRae,

Thanks for reaching out.
The LIKE will compare the string as a part of it, and that is why the 149 and the 25149 are the same. I would suggest you use the = in place of LIKE which will compare the exact value and return.

Hope it helps.
Thanks

I tried meta_compare== and that broke the looper, also removing it totally from the query breaks it too, even though default is supposed to be equals.

Probably something easy I am missing :slight_smile:

Hello @xRae,

Please check out this codex:

And if you are trying to exclude the current post from your Looper, this old thread might help:

Kindly let us know how it goes.

Yeah, I used those pages previously to get this to work. This is the looper query I use.

post_type=event&posts_per_page=12&meta_key=locale&meta_value={{dc:post:id}}&meta_compare=LIKE

Works just fine to list all ACF relations of the post type ‘events’ with the single of the post type currently displaying, except the one issue of matching numbers inside post ids.

I tried to replace meta_compare=LIKE with meta_compare==

It breaks. So i tried removing it totally since the default should be equals, but that breaks it too.

How does one use the ‘=’ that would be used in an args array ( ‘meta_compare’ => ‘=’) inside the looper query, or is it even possible?

Hey @xRae,

The compare LIKE is correct to address your issue but you need to serialize the data so that it will get the exact value. I believe your query is like this one:

$query = new WP_Query(array(
    'post_type' => 'event',
    'posts_per_page' => 12,
    'meta_query' => array(
      array(
        'key' => 'locale',
        'compare' => 'LIKE',
        'value' => get_the_ID() 
      )
    )
  ));

But the correct query should be like this one, the value is stored inside "".

$query = new WP_Query(array(
    'post_type' => 'event',
    'posts_per_page' => 12,
    'meta_query' => array(
      array(
        'key' => 'locale',
        'compare' => 'LIKE',
        'value' => '"' . get_the_ID() . '"'
      )
    )
  ));

From that code, you will have now an idea and create your own query string.

Hope that helps.

I am not using the custom looper provider with a hook. I was trying to use the query string looper provider, but it doesn’t allow you to use =, only LIKE.

If I have to write a function for this I guess I can, but it seems overkill when everything works already, except not being able to use ‘=’ in the query string looper.

Hi @xRae,

You can convert the WP query above into a query string, it is just an example of how to get the proper ID using the LIKE compare. That being said, would you mind sharing your admin credentials so that we can check on your setup and test it properly? To do that, please give us the following information in a Secure Note.

  • WordPress Login URL
  • Admin level username and password
  • Page URL or Layout Builder Name

You can find the Secure Note button at the bottom of your posts.

Thank you.

I already tried what you said on a previous thread about this, but it simply doesn’t work in the Query String Looper Provider. It breaks unless it is written exactly how I have it.

I’ll just write a function for the custom looper provider, thanks.

Hi @xRae,

Great and you’re welcome! If you have any other concerns or clarifications regarding our theme features, feel free to open up a new thread.

Thank you.

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