WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In my plugin I'm doing:

function get_user_strains()
    $userID = get_current_user_id();

    $args = array(
        'post_type'     => 'strain',
        'orderby'       => 'post_date',
        'order'            => 'DESC',
        'post_status'      => 'publish',

    $strains = get_posts($args);

    global $userStrains;
    $userStrains = array();

    foreach($strains as $i)
        $meta = get_post_meta($i->ID);
        if($i->post_author == $userID)
            $i->type = $meta['type'][0];
            $i->rating = $meta['rating'][0];
            array_push($userStrains, $i);

    $userStrainsJson = json_encode($userStrains);



function edit_strain()
    if(is_page()) echo "IS A PAGE";
    $id = isset($_GET['id']) ? $_GET['id'] : 'no id set';

    global $editStrainData;
    $editStrainData = get_post($id);
    global $editStrainMeta;
    $editStrainMeta = get_post_meta($id);


I'm trying to determine if a custom template I made is a page. Using or not using "The Loop" in my template page does not make a difference.

In edit_strain() is_page() is returning false. Does it have something to do with me using get_posts in get_user_strains()? I've heard I should be using WP_Query() but I don't really know how to convert that get_posts() into a WP_Query().

Would this be the problem?
I have searched Stack Exchange and couldn't find anything that solved my issue.

share|improve this question
up vote 5 down vote accepted

The action init happens too early to know if the current page should display a page. You have to wait at least until template_redirect. But if you want to print something to the page, use the_content.

share|improve this answer
Want to be pedantic and annoying: conditional tags start working on pre_get_posts :) – gmazzap Sep 22 '13 at 1:57
@G.M. They can still be overwritten there. – toscho Sep 22 '13 at 2:04
nice thanks. i don't know why i didn't see those events when i looked... probably just dumb. thanks! – Timothy Owen Sep 22 '13 at 23:15

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.