WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] What Post? Or is this a search Page? (2 posts)

  1. Dan.LaSota
    Member
    Posted 4 years ago #

    <?php
    	global $wpdb;
    	global $wp_query;
    	$postID = $wp_query->post->ID;
    	$queryStr = "select meta_value from wp_postmeta where meta_key = 'sectionNav' AND post_id ='" . $postID . "';";

    I am executing this code outside the loop and am trying to figure out what the current postID is of the page being drawn.

    The code above returns the postID from searches, however.
    http://www.mysite.com/s=searchTerm
    (for instance).

    What reliable way is there to determine if the page being drawn has a particular metakey? (The code above on search pages seems to return a postID, that is the problem).

  2. Dan.LaSota
    Member
    Posted 4 years ago #

    is_search() works with

    <?php if (!is_search()) {
    	global $wpdb;
    	global $wp_query;
    	global $post;
    	$postID = $wp_query->post->ID;

Topic Closed

This topic has been closed to new replies.

About this Topic