WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] get_queried_object() returns NULL during pre_get_posts (5 posts)

  1. Goce Mitevski
    Member
    Posted 8 months ago #

    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().

  2. remi5737
    Member
    Posted 8 months ago #

    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

  3. Andrew Nacin
    Lead Developer
    Posted 8 months ago #

  4. Goce Mitevski
    Member
    Posted 8 months ago #

    Thanks Andrew! Is a fix coming anytime soon?

  5. Goce Mitevski
    Member
    Posted 7 months ago #

    Fixed with WordPress 3.8.1. Thanks!

    http://wordpress.org/news/2014/01/wordpress-3-8-1/

Reply

You must log in to post.

About this Topic