Support » Plugin: Relevanssi - A Better Search » post_parent__not_in doesn’t work with relevanssi_do_query

  • Resolved Rasso Hilber

    (@nonverbla)


    Hi there,

    While testing Relevanssi for the first time, using a hierarchical custom post type and a custom WP_Query, I stumbled over an issue: It seems like relevanssi_do_query doesn’t respect the query parameter post_parent__not_in. This is what I tried, but it still gives me back posts with post_parent set to 0:

    
    $q = new \WP_Query(array_merge( array(
      's' => 'searchterm',
      'posts_per_page' => 10,
      'post_type' => 'product',
      'post_parent__not_in' => array(0),
    )));
    $posts = relevanssi_do_query( $q );
    
    • This topic was modified 5 years, 6 months ago by Rasso Hilber.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Mikko Saari

    (@msaari)

    Relevanssi does respect post_parent__not_in, just not for value 0. That’s a bug, and will be fixed in the next version.

    If you want it fixed now, find this line in Relevanssi lib/searching.php:

    if ( ! empty ( $query->query_vars['post_parent__not_in'] ) ) {

    and change it to

    if ( isset( $query->query_vars['post_parent__not_in'] ) ) {

    That should make your code work.

    Plugin Author Mikko Saari

    (@msaari)

    Actually, couple of more fixes are necessary:

    if ( ! empty( $parent_query['parent not in'] ) ) {

    should be

    if ( isset( $parent_query['parent not in'] ) ) {

    and

    $posts = implode( ',', $valid_values );
    if ( ! empty( $posts ) ) {

    should be

    $posts = implode( ',', $valid_values );
    if ( isset( $posts ) ) {

    I think those are enough. In any case, the next version will fix this. I’ll try to get the fixed version to the GitHub repo shortly.

    Plugin Author Mikko Saari

    (@msaari)

    It turned out a bit more complicated than that. But here’s the correct version from the repo: https://github.com/msaari/relevanssi/blob/master/lib/search.php

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘post_parent__not_in doesn’t work with relevanssi_do_query’ is closed to new replies.