if ( 'ourproducts' == get_post_type() ) {
Is how I’ve run post type checks….
Thank you for your response but it is still return “No”
Here is the code I used to create the post type again:
[Code moderated as per the Forum Rules. Please use the pastebin]
Thank you!!
Your code is being deliberately moderated, per the forum rules that are linked
Anyway, I did see how your CPT was registered, nothing there of concern that I saw.
I think the bigger question is, in what context is the post type check being run? I know its in functions.php, but in what context? When is it running?
Depending on the situation, you mauy need to global $post before that
Thank you very much for your reply. I just have add it into the functions.php as is like below… I didn’t use add_action/init or anything, should I?
I edited the code below to include global $post;, still no luck… hopefully this will show..
global $post;
if ($post->post_type == 'ourproducts') {
echo "<p>Yes</p>";
} else{
echo "<p>No</p>";
}
What are you trying to do with the code? Are you making some larger function?
Usually a check like that would be run inside an actual template, like index.php or single.php, unless being used within a function of some sort, and that would need to hooked appropriately so it doesn’t fire before the post type is determined
I want to make all the pages that has the custom type “ourproducts” to add a “current” class to the link on the main nav (probably some other stuff down the road.)
So that’s why I try to check if the current post is registered with the “ourproducts” class, then do this with jquery..
I have use this function in my other templates, and it works.
$post_types=get_post_types('','names');
if (in_array('ourproducts', $post_types)){
echo 'I found ourproducts!';
}
I have 4-5 templates so I don’t want to have to do 4-5 times .. that’s why I’d like to include this in the functions.php.
Is there a better way?? thank you!!
Hmm…. well… I’m probably stumped
Checking for post type is easy using the above code, within the loop
Testing for post type outside the loop is easy, if you have a specific post ID
I’m not sure exactly how to do what you are after
Thank you Voodoo. I guess I’ll just have to do this in each templates..
thanks again for your help!