If I understand you correctly, you want some default content if you create a new post in the category "store".
Try to use the_content()
filter here:
add_filter( 'the_content', 'add_default_content' );
function add_default_content( $content ) {
//run only when we are in the category "store"
//could also be "coupons"
if ( in_category('store') ) {
//define your default text here
$default = 'My default content is here.';
// this will display the new default content first,
// after that the normal post-content you entered in the post-editor will be shown
$content = $default . $content;
}//END if is category
return $content;
}
This will check if the current post is in that category.
Look at the line $content = $default . $content;
This line will first show our new default content ($default
) and after this, it will display the post-editor content ($content
).
If you have not entered any content in the post-editor, only the default text will show.
You can also rearrange this line too:
$content = $content . $default;
In this case, the post-editor content will show first, and after this our default text.
So you could create 2 function, one for content before the post-editor and one after.
Update:
@sammy , OK, I just had a look at your site.
It seems you are using a theme from http://www.premiumpress.com.
The code I posted above works for normal post categories, if you are using a custom type, taxonomies an terms, please try something like this:
if ( has_term('term-slug', 'taxonomy-slug') ) { ... }
Update 2:
You said 'store'
is a taxonomy, so I just tested this:
I created a new taxonomy called 'store'
and added some terms to that taxonomy.
I edited some posts, and added some of the new store-taxonomy terms to these posts.
I added this code to my functions.php
:
add_filter( 'the_content', 'add_default_content' );
function add_default_content( $content ) {
// only show the default content if the post is in taxonomy 'store'
// true if the current post has any of the given terms (or any term, if no term is specified)
// we leave 'term' empty, we just specify the taxonomy
if ( has_term( '', 'store' ) ) {
//define your default text here
$default = 'This is the default content.';
// this will display the new default content first,
// after that the normal post-content you entered in the post-editor will be shown
$content = $default . $content;
}//END if has_term
return $content;
}
After this, I see the new content "This is the default content.", only on posts which are using the 'store'
taxonomy. Regardless of which term is added.
As you can read in the codex, if we dont specify any term, the has_term()
function will check if the post has any term of the taxonomy. So has_term()
returns true.