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.

First time posting here...

I am trying to figure out if there is a hook or action that I can use when a user goes to wp-admin/post.php... Basically when the user goes to post.php I want to check if there is a &from=1 variable and add that to post_meta

Thanks!

$from = $_GET['from'];
$post_id = $_GET['post'];
if($from == 1){
  add_post_meta($post_id, 'EDITED', 'true');
}
share|improve this question

1 Answer 1

up vote 1 down vote accepted

You can add your code to the init action hook and check global $pagenow variable:

add_action( 'init', 'wpse8170_check_from_var' );
function wpse8170_check_from_var() {
    global $pagenow;

    if ( 'post.php' != $pagenow || ! isset( $_GET['post'] ) || ! isset( $_GET['from'] ) || 1 != (int) $_GET['from'] ) {
        return;
    }

    update_post_meta( (int) $_GET['post'], 'EDITED', 'true' );
}
share|improve this answer
    
Updated your code. Removed the pull get_post() as the check is not needed because if the post id doesn't exist update_post_meta() will take care of that. Also took care of your if statements so no longer deeply nested. –  Brady Jun 8 '12 at 15:07
    
thanks @Brady, you are right –  Eugene Manuilov Jun 8 '12 at 15:10
    
Thanks guys! your both awesome –  Greg Jun 8 '12 at 15:42
    
Why did you re-edit and add {} to the if statement? They are not needed if the code running, when the condition is met, is one line only. –  Brady Jun 8 '12 at 15:43
    
@Brady I prefer to use brace even for one line only. It enhances readability and makes code styles look the same. –  Eugene Manuilov Jun 8 '12 at 16:16

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.