• Resolved Darren Cooney

    (@dcooney)


    Hi,
    I’m trying to debug an issue with a custom Relevanssi search form where setting 'fields' => 'ids' is not working.

    The following code simply searches for a movie post type by term. You can see in the comments where things are getting messy.

    $args = array(
    	'post_type' => array('movie'),
    	'fields' => 'ids',
    	's' => $term,
    ); 
    $wp_query = new WP_Query($args);
    // print_r($wp_query->posts) // Returns array of post IDs [PERFECT!]
    
    relevanssi_do_query($wp_query);
    // print_r($wp_query->posts); // Returns a WP_POST Object array [BOO!]
    
    // Parse the query
    //... Code removed, not needed for this example.
    

    After the relevanssi_do_query function is run, the array of posts is no longer just post IDs but has been converted to a WP_POST object.

    I dug into the plugin and confirmed ids is the value of the fields param in the search() method.

    Any ideas why this would be happening?

    Cheers and thanks in advance!

    • This topic was modified 6 years, 9 months ago by Darren Cooney.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Mikko Saari

    (@msaari)

    If this is not working, looks like there’s a bug in Relevanssi. Once I get to my testing setup tomorrow, I’ll take a look at this.

    Plugin Author Mikko Saari

    (@msaari)

    Sorry, but I can’t reproduce this. On my test site, setting fields to ids is returning an array of post IDs as expected. Which version of Relevanssi are you using?

    If you look at the return values of the relevanssi_search() function, does the $return[‘hits’]?contain post objects or post IDs?

    In the relevanssi_do_query() function, if you take a look at this:

    $filter_data = array($hits, $q);
    $hits_filters_applied = apply_filters('relevanssi_hits_filter', $filter_data);
    $hits = array_values($hits_filters_applied[0]);

    What kind of data does the $hits variable contain?

    Thread Starter Darren Cooney

    (@dcooney)

    Hi @msaari,
    I appreciate you taking the time for this.

    This issue appears to be very sporadic across different hosting environments.

    Because of this, I’m just going remove the ‘fields’=>’ids’ from the query and then parse the results in a foreach loop to grab the post IDs.

    Cheers,

    Plugin Author Mikko Saari

    (@msaari)

    If it does appear, I’d look to see if there’s a relevanssi_hits_filter filter function messing it up. If there’s a function on that filter hook that doesn’t care about the fields parameter, you’ll quite likely end up with post objects in the array.

    If you can come up with a problem that can be reproduced, ping me.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Issue with returning Field IDs not working’ is closed to new replies.