WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. fredhead
    Member
    Posted 2 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:

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

    http://wordpress.org/support/topic/how-to-get-query-string

    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?

    Thanks!

  2. esmi
    Forum Moderator
    Posted 2 years ago #

    Get the post_type from the $post object.

  3. fredhead
    Member
    Posted 2 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:

    http://www.rlmseo.com/blog/wordpress-post-variable-quick-reference/

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

Topic Closed

This topic has been closed to new replies.

About this Topic