[resolved] Retrieve post_type querystring value? (3 posts)

  1. fredhead
    Posted 5 years ago #

    I need to retrieve the post_type querystring value so that I can display the appropriate page heading on my archive page based on content type. I've confirmed the querystring values exist using this code from the forum:

    echo "<pre>"; print_r($wp_query->query_vars); echo "</pre>";


    However, when I use $_GET to grab the querystring value like this:

    $post_type = $_GET[post_type];

    I get no value. What is the secret to capturing WordPress querystring values for this kind of task?


  2. esmi
    Forum Moderator
    Posted 5 years ago #

    Get the post_type from the $post object.

  3. fredhead
    Posted 5 years ago #

    To clarify Esmi's suggestion, this works:

    $page_type = $post->post_type;

    But this also appears to work:

    $page_type = get_query_var('post_type');

    I found a list of $post values here:


    Thanks, Esmi, for at least the direction ...

Topic Closed

This topic has been closed to new replies.

About this Topic