Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm trying to restrict how many items you can associate with a post so in my save function I have:

add_action( 'save_post', array( $this, 'save_custom_items_data' ), 10, 2 );

public function save_custom_items_data( $post_id, $post ) {
    if(count($related_items) > 5) {
        // display error message here but the page redirects anyway...
    } else {
        update_post_meta( $post_id, '_custom-meta-items', $related_items );
    }
}

how do I display an error here instead of saving the custom post meta?

share|improve this question
2  
There's not enough code here to be useful. –  vancoder Apr 8 '13 at 21:14
    
added some more code –  keeg Apr 9 '13 at 19:49

1 Answer 1

up vote 2 down vote accepted

Short of doing some jQuery validation, I think the only option is wp_die().

add_action( 'save_post', array( $this, 'save_custom_items_data' ), 10, 2 );

public function save_custom_items_data( $post_id, $post ) 
{
    if( count( $related_items ) > 5 ) 
    {
        wp_die(
            'Error, 5 items max.', 
            'Error',  
            array( 
                'response' => 500, 
                'back_link' => true 
            )
        );    
    } 
    else 
        update_post_meta( $post_id, '_custom-meta-items', $related_items );
}

Related Q&A's:

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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