Support » Fixing WordPress » get_queried_object() returns NULL during pre_get_posts

  • Resolved Goce Mitevski

    (@gocemitevski)


    Is get_queried_object() / get_queried_object_id() supposed to return NULL during ‘pre_get_posts’?

    Once I updated to WordPress 3.8, some parts of a theme I’m developing stopped working, as those depend on get_queried_object() / get_queried_object_id().

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi I’d like o confirm Mitevski’s finding.

    I find that in pre_get_posts get_queried_object is NULL always on category pages.
    Furtermore get_queried_object_id and query_vars[‘category_name’] do return results depending on permalinks configuration.

    I find for add_action( ‘pre_get_posts’, function( $query ) {
    the following behaviour:

    Permalinks off behaviour:
    Url: /?cat=80


    var_dump( $query->get_queried_object_id ());
    int(80) string(0) ""

    var_dump( $query->query_vars['category_name']);
    string(0) ""

    var_dump( $query->get_queried_object ());
    NULL

    Permalinks on behaviour:
    Url: /category/december


    var_dump( $query->get_queried_object_id ());
    string(0) ""

    var_dump( $query->query_vars['category_name']);
    string(8) "december"

    var_dump( $query->get_queried_object ());
    NULL

    Moderator Andrew Nacin

    (@nacin)

    Thanks Andrew! Is a fix coming anytime soon?

    Fixed with WordPress 3.8.1. Thanks!

    WordPress 3.8.1 Maintenance Release

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘get_queried_object() returns NULL during pre_get_posts’ is closed to new replies.