• setick

    (@setick)


    hi,

    I am fetching posts with the custom field with either word_count > 1000 or number_count > 1.

    Very basic query.

    Code below:

    $args = array(
    'post_type' => 'post',
    'posts_per_page' => 8,
    'meta_query' => array(
    'relation' => 'OR',
    array(
    'key' => 'word_count',
    'value' => 1000,
    'type' => 'NUMERIC',
    'compare' => '>'
    ),
    array(
    'key' => 'number_count',
    'value' => 1,
    'type' => 'NUMERIC',
    'compare' => '>'
    ),
    ),
    );

    $posts = get_posts($args); ## working as expected
    $posts = get_crp_posts($args); ## fetch 0 posts

    get_posts() works as expected but get_crp_posts() fetches no posts, I been testing multiple times but canot fix it.

    get_crp_posts() can work with only one meta_query condition but cannot handle OR relation.

    Please have a look.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter setick

    (@setick)

    my current workaround is to get all the post_ids using original get_posts() with multiple queries, merging them and use get_crp_posts() with post__id_in to get the related posts i need.

    It works but I also expect to get it directly from your plugin.

    thanks

    Plugin Author Ajay

    (@ajay)

    You’re correct that this should work – so I suspect this might be a bug in the way the meta_query is handled within my plugin.

    Are you able to tell me what are the Query Monitor resulting queries for each of the above functions?

    Also, I need to find a way to replicate this in my test installs – is there a way for me to generate these fields?

    Thread Starter setick

    (@setick)

    uh, i have custom functions for these fields, they are generated automatically after each save_post() action. Basically I count the word count and shortcode count for each posts and save them in custom fields, nothing particular.

    I think you can just make 2-3 dummy posts, with some manually added custom fields to test it out. Very easy to replicate.

    If you face any issues trying to replicate, hit me up. I will set a tastewp test site for you.

    Plugin Author Ajay

    (@ajay)

    Thanks – that helps. I’ll try to create some meta fields and try to see what I can do about this. Will get back.

    Plugin Author Ajay

    (@ajay)

    @setick

    I’ve been relooking at the code and I think it needs some optimisation to get it to work with the multiple meta_queries as you have there. Would you be in a position to test a beta version once I have this fixed?

    Plugin Author Ajay

    (@ajay)

    I’ve pushed through a related posts version: https://github.com/WebberZone/contextual-related-posts/releases/tag/v3.5.3-beta1 which has a file that can be used to replace the beta version.

    I have been running the tests and noticed one key difference between the two functions: the related posts matching algorithm limits the number of posts so worth checking if you’re getting posts without the meta_query first using get_crp_posts. And then add the meta_query to see if this works.

    Thread Starter setick

    (@setick)

    your beta would fix it according to your code.

    Will test on monday and get back.

Viewing 7 replies - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.