Default content for a post in one category?

This is a common function that adds default text to all posts:

add_filter( 'default_content', 'my_editor_content' );
function my_editor_content( $content ) {
    $content = "default content goes here....";
    return $content;
}

How would this be changed to add the default content only to a post in one category?

4/10/11 Not an exact answer, but a few choices below in my own answer

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

One possibility is this question/answer here by Jan Fabry, which asks for the default content in the process of creating the new post:
Force category choice before creating new post?

I ended up using a Quicktag as a way of easily getting the content into a post, and because the default content happened to be html, it works as good as it can for now. But in the future there turns out to be a way to get default content into a post when that post is saved in that category, that will be good.

Quicktags function for functions.php:

//Custom Quicktags Function

function my_quicktags() {
    wp_enqueue_script('custom_quicktags',
    get_bloginfo('template_directory').'/custom-quicktags.js', array('quicktags'));
}
add_action('admin_print_scripts', 'my_quicktags');

Sample Quicktags code for custom-quicktags.js, which goes in the theme folder:

edButtons[edButtons.length] =
new edButton('newbutton1'
,'TagButtonName'
,'html, like <div>'
,'and more </div>'
,''
);

Method 2

You can globalize $post and check if it has the category you want:

add_filter( 'default_content', 'my_editor_content' );
function my_editor_content( $content ) {
    global $post;
    $the_one_category_id= '12'; //the category you want this to work on id
    $args= array('orderby' => 'name', 'order' => 'ASC', 'fields' => 'ids');
    $cats = wp_get_object_terms($post->ID, 'category',$args);
    if (in_array($the_one_category_id,$cats)){
        $content = "default content goes here....";
    }
        return $content;
    }


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x