• Resolved kiranime

    (@kiranime)


    Hello, today i notice when rank math is active, the query for my custom taxonomy is not correct.

    here’s the problem:

    - rank math not active // wp_query->request
    SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts LEFT JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) WHERE 1=1 AND ( wp_term_relationships.term_taxonomy_id IN (39)) AND wp_posts.post_type = 'anime' AND ((wp_posts.post_status = 'publish')) GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0, 20
    
    - when active
    SELECT SQL_CALC_FOUND_ROWS  wp_posts.ID FROM wp_posts  WHERE 1=1  AND (  0 = 1 ) AND wp_posts.post_type = 'anime' AND ((wp_posts.post_status = 'publish')) GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0, 20

    any idea how is that happen?

    thank you.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Support Rank Math Support

    (@rankmathteam)

    Hello @kiranime,

    Thank you for your query and we are so sorry about the trouble this must have caused.

    We would like to ask for further details when this issue is happening. Can you please let us know the complete steps you did until you discover that our plugin is changing the query?

    Also, share with us the custom taxonomy query code you have on your website.

    We really look forward to hearing back from you. Thank you.

    Thread Starter kiranime

    (@kiranime)

    1. my user inform me that the taxonomy (genre) page is empty.
    2. I tried to debug using debug log and notice that the request query does not include relationship.
    3. as usual for debugging, I deactivate all plugin and try one by one.
    4. all seems good and i get the correct query request, untill i activate rank math then the query changed.

    the query:

    [
    'post_type'=> 'anime',
    'post_status'=> 'publish',
    'paged' => $page, 
    'tax_query' => [
               [
                 'taxonomy' => $tax_name, 
                 'field' => 'term_id', 
                 'terms' => $id, 
                 'operator' => 'IN'
               ]
    ], 
    'posts_per_page' => get_theme_mod('__archive_count', 20)
    ]
    Thread Starter kiranime

    (@kiranime)

    I think i know the different, the tax query is way off if the plugin active.

    $current        = get_queried_object();
    $id             = $current->term_id;
    $page           = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $tax_name       = $current->taxonomy;

    the query (in json from echo):

    "query": {
    			"post_type": "anime",
    			"paged": 1,
    			"tax_query": [
    				{
    					"taxonomy": "genre",
    					"field": "term_id",
    					"terms": 27,
    					"operator": "IN"
    				}
    			],
    			"posts_per_page": 20
    		}

    tax_query without the plugin:

    "tax_query": {
    			"queries": [
    				{
    					"taxonomy": "genre",
    					"terms": [27],
    					"field": "term_id",
    					"operator": "IN",
    					"include_children": true
    				}
    			],
    			"relation": "AND",
    			"queried_terms": {
    				"genre": {
    					"terms": [27],
    					"field": "term_id"
    				}
    			},
    			"primary_table": "wp_posts",
    			"primary_id_column": "ID"
    		},

    With the plugin active, the $id variable is different. in the correct query it’s 27 but if plugin active, the $id will be 227 even if i am using get_queried_object_id() or using $current->term_id.

    Thread Starter kiranime

    (@kiranime)

    I found out the issue, the get_header() must be on top of the file. Otherwise, and i don’t know why it’ll change the queried id.

    Plugin Support Rank Math Support

    (@rankmathteam)

    Hello @kiranime,

    You mention that with the plugin active you get the value of the queried object with a different ID. Can you please let us know what the ID that you get with the plugin enabled refers to? Is that a page that belongs to this custom taxonomy?

    This would help us better understand what might be changing the current WP Query from our side.

    Thank you.

    Thread Starter kiranime

    (@kiranime)

    when the plugin active the term_id become 227…

    Plugin Support Rank Math Support

    (@rankmathteam)

    Hello @kiranime,

    Can you please confirm if the ID(227) belongs to a different term or a page that belongs to this custom taxonomy?

    Looking forward to helping you.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘tax_query getting ignored on wp_query when rank math active’ is closed to new replies.