1

I have a custom post type, when I try to display the post, I get redirected to the homepage. The same happens to my blog posts

I enabled Twenty Eleven theme, that works fine, so there's a problem with the theme I'm using.

I was trying to debug query vars using

add_action('pre_get_posts','test_aaa',1);
function test_aaa() {
    global $wp_query;
    var_dump($wp_query->query_vars);
    die('');
}

That always gives me page_id = 60, which is my homepage. How can I debug this and find out what is wrong?

This are the complete query vars I'm getting:

array(53) { ["page"]=> string(0) "" ["paged"]=> int(0) ["error"]=> string(0) "" ["m"]=> string(0) "" ["p"]=> int(0) ["post_parent"]=> string(0) "" ["subpost"]=> string(0) "" ["subpost_id"]=> string(0) "" ["attachment"]=> string(0) "" ["attachment_id"]=> int(0) ["name"]=> string(0) "" ["static"]=> string(0) "" ["pagename"]=> string(0) "" ["page_id"]=> string(2) "60" ["second"]=> string(0) "" ["minute"]=> string(0) "" ["hour"]=> string(0) "" ["day"]=> int(0) ["monthnum"]=> int(0) ["year"]=> int(0) ["w"]=> int(0) ["category_name"]=> string(0) "" ["tag"]=> string(0) "" ["cat"]=> string(0) "" ["tag_id"]=> string(0) "" ["author"]=> string(0) "" ["author_name"]=> string(0) "" ["feed"]=> string(0) "" ["tb"]=> string(0) "" ["meta_key"]=> string(0) "" ["meta_value"]=> string(0) "" ["preview"]=> string(0) "" ["s"]=> string(0) "" ["sentence"]=> string(0) "" ["title"]=> string(0) "" ["fields"]=> string(0) "" ["menu_order"]=> string(0) "" ["embed"]=> string(0) "" ["category__in"]=> array(0) { } ["category__not_in"]=> array(0) { } ["category__and"]=> array(0) { } ["post__in"]=> array(0) { } ["post__not_in"]=> array(0) { } ["post_name__in"]=> array(0) { } ["tag__in"]=> array(0) { } ["tag__not_in"]=> array(0) { } ["tag__and"]=> array(0) { } ["tag_slug__in"]=> array(0) { } ["tag_slug__and"]=> array(0) { } ["post_parent__in"]=> array(0) { } ["post_parent__not_in"]=> array(0) { } ["author__in"]=> array(0) { } ["author__not_in"]=> array(0) { } }
  • The query_vars seem to be empty, so that would indeed lead you to the home page. What is the code generating the query_vars? – cjbj Aug 18 '16 at 16:25
  • I guess the redirect happens sooner than the pre_get_posts is firing. – user1049961 Aug 18 '16 at 16:38
1

The staple technique to debug an unwanted redirect is to interrupt it in process and dump a call stack of where it's initiated from.

Outside of just doing it by hand by troubleshooting WP core's redirect functions, there are some ready made solutions. Better HTTP Redirects is one plugin I've used on multiple occasions for it, it has debug mode that will do just that.

  • This helped me a lot! Thanks, great suggestion, great plugin. – user1049961 Aug 18 '16 at 20:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.