0

I have some custom JavaScript on the admin side, on for counting the posts, the other for checking if a checkbox have been ticked.

$('.inside input').on('click', function() { 
        if ($(this).is(':checked')) {
        console.log('checked');
            $('#title').val('overview');
        } else {
            $('#title').val(title);
        }
    });

the other one

$('#postexcerpt').find('textarea').on('keyup', function(e) {

        max_chars = 240 - $(this).val().length;
        if (max_chars < 1) {

            $(this).val($(this).val().substr(0,238));
        }
        $('#counterbox').html(max_chars);

    });

The codes above are working. My problem is when I save the post, CPT or any other post type the Title field does not get saved? Any ideas on this?

Update - Saving CPT

add_action('save_post','save_press_meta');

function save_press_meta() { global $post; $post_id = $post->ID;

if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;

    if( isset( $_POST['paper'] ) )  
    update_post_meta( $post_id, 'paper',$_POST['paper']);

    if( isset( $_POST['press_article_thumbnail'] ) )  
    update_post_meta( $post_id, 'articlethumbnail',$_POST['press_article_thumbnail']);

    if( isset( $_POST['press_article_content'] ) )  
    update_post_meta( $post_id, 'articlecontent',$_POST['press_article_content']);      

    if( isset( $_POST['press_article_pubtime'] ) )  
    update_post_meta( $post_id, 'articlepubtime',$_POST['press_article_pubtime']);      

}

  • Can i look at your code for saving posts – Balas Dec 31 '13 at 12:31
  • Code is updated – Attila Olah Dec 31 '13 at 13:02
  • Where is this checkbox, and .inside, this class is used by WordPress as well for publish button wrapper, your js will conflict. See if you are getting some js error in console – sven Dec 31 '13 at 13:55
1

I think the problem lies here,

 $('.inside input').on('click', function() { 
    if ($(this).is(':checked')) {
$('#title').val('overview'); } else { $('#title').val(title); } });

".inside input" in your javascript code is checkbox?
If yes then, it will also apply to publish button. So when you click publish button,above js will be called and will change the title.
Use some id or specific class other than ".inside".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.