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.

1 Answer 1


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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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