While I am in a custom post admin 'add post' page, I generate a title from the check taxonomies for that post. Then I replace the post_title with the generated title, and I want to insert that title in the beginning of the post content as well.
I got it to work, except that it doesn't insert it in the post content.
I used the same function for replacing the title and the content.
The below code works in that the title of the post is replaced, but the content is not.
I thought the jQuery would do it, but maybe the content works differently, or I used the wrong process.
Can someone help me?
Here is the HTML:
//Add CARS meta boxes
add_action( 'add_meta_boxes' , 'car_meta_boxes' );
function car_meta_boxes() {
add_meta_box(
'car_info',
__( 'Car Info'),
'car_info_div',
'cars'
);
}
function car_info_div( $post ) {
// Use nonce for verification
wp_nonce_field( plugin_basename( __FILE__ ), 'car_noncename' );
//CARS Data Entry Fields
?>
<div>
<label for="car_calc_name"><?php _e("Car Name");?></label>
<input type="text" name="car_calc_name" value="<?php echo get_post_meta($post->ID, 'car_calc_name', true);?>" /><br>
<label for="car_calc_color"><?php _e("Car Color");?></label>
<input type="text" name="car_calc_color" value="<?php echo get_post_meta($post->ID, 'car_calc_color', true);?>" /><br>
<label for="car_calc_series"><?php _e("Car Series");?></label>
<input type="text" name="car_calc_series" value="<?php echo get_post_meta($post->ID, 'car_calc_series', true);?>" /><br>
<label for="car_calc_descript"><?php _e("Car Discription");?></label>
<input type="text" name="car_calc_descript" value="<?php echo get_post_meta($post->ID, 'car_calc_descript', true);?>" /><br>
<input type="button" value="Create" id="create" />
<input type="button" value="Replace" id="replace" />
</div>
<script type="text/javascript">
Then the PHP:
// Cars REPLACE Button
jQuery('#replace').click(function(){
//get the parts of the title
var cname = jQuery('input[name="car_calc_name"]').val();
var ccolor = jQuery('input[name="car_calc_color"]').val();
var cseries = jQuery('input[name="car_calc_series"]').val();
var cdescript = jQuery('input[name="car_calc_descript"]').val();
//Update title
var title = cname + ' - ' + ccolor + ' - ' + cseries + ' - ' + cdescript;
jQuery('input[name="post_title"]').focus().val(title);
jQuery('input[name="post_content"]').focus().val(title);
});
//-->