Update status of all posts in a category

I am sure there’s an easier way to accomplish this, but this how I would’ve done. Query all posts with category X and status X Update query results with status Y. $target_category = ‘news’; $change_status_from = ‘draft’; $change_status_to = ‘publish’; $update_query = new WP_Query(array(‘post_status’=>$change_status_from, ‘category_name’=>$target_category, ‘posts_per_page’=>-1)); if($update_query->have_posts()){ while($update_query->have_posts()){ $update_query->the_post(); wp_update_post(array(‘ID’=>$post->ID, ‘post_status’=>$change_status_to)); } } You can … Read more

Display author name, outside the loop, if they haven’t published a custom post

author’s name or logged in user’s name? can use global $current_user; or wp_get_current_user(); if the user is logged in. if( is_user_logged_in() ) { $current_user = wp_get_current_user(); echo $current_user->user_firstname; } for specific user role you can check $current_user->roles array. Reference: https://codex.wordpress.org/Function_Reference/wp_get_current_user https://codex.wordpress.org/Function_Reference/get_currentuserinfo

problem with publish date not always appearing [duplicate]

From the the_date() documentation: Will only output the date if the current post’s date is different from the previous one output. i.e. Only one date listing will show per day worth of posts shown in the loop, even if the function is called several times for each post. [Emphasis mine] You’re almost certainly looking for … Read more

Do action for only switch status for publish_post

You can use the transition_post_status hook, which is fired whenever the status is changed. So to perform an action when the status is changed to publish, you’d do this: function notificationApprove( $new_status, $old_status, $post ) { if ( ‘publish’ === $new_status && ‘publish’ !== $old_status && ‘post’ === $post->post_type ) { // Send mail } … Read more

transition_post_status hook doesn’t have any POST data when publish with Gutenberg [closed]

But you shouldn’t use $_POST inside that hook. transition_post_status fires when a post is transitioned from one status to another. It can be caused by anything (not only by sending POST request from editor). For example here’s the function that is responsible for publishing future posts: check_and_publish_future_post. It’s called only by cron, without sending any … Read more

Do action on publish or update?

Why don’t you wrap it in post save_post and post_publish hooks? You have examples here: http://codex.wordpress.org/Function_Reference/add_action How to do it: Add this to your functions.php file: function my_data_update () { $company = get_field(‘company_name’); $address = get_field(‘address’); $city = get_field(‘city’); $post_code = get_field(‘post_code’); //etc etc… } add_action(‘publish_post’, ‘my_data_update’); add_action(‘save_post’, ‘my_data_update’);

Condition display metabox in case the post is saved

As an alternative to @m0r7if3r’s solution, the add_meta_boxes hook optionally passes two variables, the post type and post object. You can use this to conditionally add your metabox. New posts have the post status of ‘auto-draft’. add_action( ‘add_meta_boxes’, ‘myplugin_add_custom_box’,10,2); function myplugin_add_custom_box($post_type, $post) { if($post->post_status != ‘auto-draft’){ add_meta_box( ‘myplugin_sectionid’, __( ‘My Post Section Title’, ‘myplugin_textdomain’ ), … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)