• Resolved nitrospectide

    (@nitrospectide)


    I have had this WP_Query in my functions.php, and it was working until I enabled Relevanssi. What might be causing the issue?

    $theLeader = new WP_Query(array(
    	'post_type' => 'leaders',
    	's' => 'Roger Deakins',
    	'search_columns' => array( 'post_title' ),
    	'order' => 'ASC',
    	'orderby' => 'title',
    	'post_status' => 'publish',
    	'posts_per_page' => 1,
    ));

    When I run the above with Relevanssi enabled, I get this output from it:

    {
        "query": {
            "post_type": "leaders",
            "s": "Roger Deakins",
            "search_columns": [
                "post_title"
            ],
            "order": "ASC",
            "orderby": "title",
            "post_status": "publish",
            "posts_per_page": 1
        },
        "query_vars": {
            "post_type": "leaders",
            "s": "Roger Deakins",
            "search_columns": [
                "post_title"
            ],
            "order": "ASC",
            "orderby": "title",
            "post_status": "publish",
            "posts_per_page": 1,
            "error": "",
            "m": "",
            "p": 0,
            "post_parent": "",
            "subpost": "",
            "subpost_id": "",
            "attachment": "",
            "attachment_id": 0,
            "name": "",
            "pagename": "",
            "page_id": 0,
            "second": "",
            "minute": "",
            "hour": "",
            "day": 0,
            "monthnum": 0,
            "year": 0,
            "w": 0,
            "category_name": "",
            "tag": "",
            "cat": "",
            "tag_id": "",
            "author": "",
            "author_name": "",
            "feed": "",
            "tb": "",
            "paged": 0,
            "meta_key": "",
            "meta_value": "",
            "preview": "",
            "sentence": "",
            "title": "",
            "fields": "",
            "menu_order": "",
            "embed": "",
            "category__in": [],
            "category__not_in": [],
            "category__and": [],
            "post__in": [],
            "post__not_in": [],
            "post_name__in": [],
            "tag__in": [],
            "tag__not_in": [],
            "tag__and": [],
            "tag_slug__in": [],
            "tag_slug__and": [],
            "post_parent__in": [],
            "post_parent__not_in": [],
            "author__in": [],
            "author__not_in": [],
            "ignore_sticky_posts": false,
            "suppress_filters": false,
            "cache_results": true,
            "update_post_term_cache": true,
            "update_menu_item_cache": false,
            "lazy_load_term_meta": true,
            "update_post_meta_cache": true,
            "nopaging": false,
            "comments_per_page": "50",
            "no_found_rows": false,
            "search_terms_count": 2,
            "search_terms": [
                "Roger",
                "Deakins"
            ],
            "search_orderby_title": [
                "wp_posts.post_title LIKE '{a016df003ee85dbbacebb4722953f1c7744204b003320f8d400ec66ed6cb7c0c}Roger{a016df003ee85dbbacebb4722953f1c7744204b003320f8d400ec66ed6cb7c0c}'",
                "wp_posts.post_title LIKE '{a016df003ee85dbbacebb4722953f1c7744204b003320f8d400ec66ed6cb7c0c}Deakins{a016df003ee85dbbacebb4722953f1c7744204b003320f8d400ec66ed6cb7c0c}'"
            ]
        },
        "tax_query": {
            "queries": [],
            "relation": "AND",
            "queried_terms": [],
            "primary_table": "wp_posts",
            "primary_id_column": "ID"
        },
        "meta_query": {
            "queries": [],
            "relation": null,
            "meta_table": null,
            "meta_id_column": null,
            "primary_table": null,
            "primary_id_column": null
        },
        "date_query": false,
        "request": "SELECT * FROM wp_posts WHERE 1=2",
        "posts": [],
        "post_count": 0,
        "current_post": -1,
        "before_loop": false,
        "in_the_loop": false,
        "comment_count": 0,
        "current_comment": -1,
        "found_posts": 0,
        "max_num_pages": 0,
        "max_num_comment_pages": 0,
        "is_single": false,
        "is_preview": false,
        "is_page": false,
        "is_archive": false,
        "is_date": false,
        "is_year": false,
        "is_month": false,
        "is_day": false,
        "is_time": false,
        "is_author": false,
        "is_category": false,
        "is_tag": false,
        "is_tax": false,
        "is_search": true,
        "is_feed": false,
        "is_comment_feed": false,
        "is_trackback": false,
        "is_home": false,
        "is_privacy_policy": false,
        "is_404": false,
        "is_embed": false,
        "is_paged": false,
        "is_admin": false,
        "is_attachment": false,
        "is_singular": false,
        "is_robots": false,
        "is_favicon": false,
        "is_posts_page": false,
        "is_post_type_archive": false,
        "thumbnails_cached": false
    }

    Start a New TextDuplicate Text

    Download RAW FileCopy Shareable URL

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter nitrospectide

    (@nitrospectide)

    I also have this code from your knowledge base in my functions.php:

    function rlv_relationship_content( $content, $post ) {
    
      // Fetching the post data by the relationship field.
      $relationships = get_post_meta( $post->ID, 'author', true );
    
      if ( ! is_array( $relationships ) ) {
        $relationships = array( $relationships );
      }
    
      foreach ( $relationships as $related_post ) {
        $content .= ' ' . get_the_title( $related_post );
      }   
    
      return $content;
    
    }
    
    add_filter( 'relevanssi_content_to_index', 'rlv_relationship_content', 10, 2 );

    Thread Starter nitrospectide

    (@nitrospectide)

    I’m being asked if I can get this working. Do you have any insight on what might be happening here?

    Plugin Author Mikko Saari

    (@msaari)

    Sorry, I’ve completely missed your original post; I didn’t get an email notification from it for some reason.

    In the original query, add relevanssi parameter and set it to true. Does that fix the problem?

    I had a simmilar problem with a custom query and adding relevanssi did thankfully fix it for me.
    Thank you very much.

    Thread Starter nitrospectide

    (@nitrospectide)

    Mikko: That did it! Thank you.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Relevanssi breaks a custom WP_Query’ is closed to new replies.