I want to echo some text on all custom post types from the same group.
The following is_singular code successfully displays the text on all CPTs:
if (is_singular () ) {
echo 'something'; }
The following is_singular code with the plugin’s CPT identifier successfully displays the text on just one specific instance of that CPT group:
if (is_singular ('tu_result_1836') ) {
echo 'something'; }
To apply it to all CPTs from the tu_result group, if I try ‘tu_result’ or ‘tu_result_’ instead of ‘tu_result_1836’, it no longer works. Do I need to use a wildcard function, e.g. ‘tu_result_*’? Or is it incorrect to use is_singular here. I have also tried all of the above combinations with is_single.
Hopefully someone can help. Thanks 🙂
Does the following works for you? :
There’s a few ways to handle what you are tying to do:
Note: All information below assumes you’ve named your custom post type
tu_result
. If not, adjust as necessary.First, you could use the Template Heirarchy System to your advantage, and create a template for your
tu_result
. If it doesn’t exist, create it – name itsingle-tu_result.php
, and it will be the template that WordPress automatically displays for any single posts that aretu_result
types.Second, you could extend your functionality slightly using the get_post_type() function, like so: