publish_post called too early

Try this workaround of this issue without using publish_post hook (using save_post) add_action( ‘save_post’, ‘wpse228941_save_post’ ); function wpse228941_save_post( $post_id ) { if( defined(‘DOING_AUTOSAVE’) && DOING_AUTOSAVE ) return; if ( “publish” == get_post_status( $post_id ) && ! get_post_meta( $post_id, “se_228941_mailed”, 1 ) ) { do_action( “sm12_publish_post”, $post_id ); update_post_meta( $post_id, “se_228941_mailed”, time() ); } } add_action( … Read more

Can we have private drafts?

I would probably create a custom field / check box for this for a draft stage. Then hook into post status transition (or around) and when post is published force it to only private, even if normal publish was pressed. From personal experience custom post statuses are a wreck. They seem like a good idea, … Read more

Disable “preview changes” button

Please replace $post_type with your post_type in question, e.g. post, page, cpt_slug,… The function echoing the meta box with the preview button is called post_submit_meta_box. The condition to show the button is set with the function is_post_type_viewable. Following that: If the {$post_type}s flags publicly_queryable or _builtin and public are set to true the preview button … Read more

get_terms on save_post hook

You’re on the right track. When you do something like this in a form.. <input name=”tax_input[formats][]” /> You create levels in the $_POST array. So you’d get the formats array like this… <?php $formats = $_POST[‘tax_input’][‘formats’]; Full example… <?php add_action(‘save_post’, ‘wpse74017_save’); function wpse74017_save($post_id) { // check nonces and capabilities here. // use a ternary statement … Read more

Is there a way to know if a post has been published through XML-RPC?

You could use a custom field for a post which is saved via XMLRPC by using the action hook xmlrpc_publish_post. wpse_from_xmlrpc() could than check this custom field. <?php add_action( ‘xmlrpc_publish_post’, ‘add_xmlrpc_postmeta’ ); function add_xmlrpc_postmeta( $post_id ){ update_post_meta( $post_id, ‘send-by-xmlrpc’, 1 ); } function wpse_from_xmlrpc( $post_id ){ $xmlrpc = get_post_meta( $post_id, ‘send-by-xmlrpc’, true ); if( $xmlrpc … Read more

Show recent published posts

The arguments you are using are wrong. They should be: $args = array( ‘numberposts’ => ’10’, ‘post_type’ => ‘post’, ‘post_status’ =>’publish’, ‘tax_query’ => array( ‘taxonomy’ => ‘category’, ‘field’ => ‘id’, ‘terms’ => array( 10, 11, 57 ), ‘operator’ => ‘NOT IN’, ) ); Or shorter: $args = array( ‘numberposts’ => ’10’, ‘post_type’ => ‘post’, ‘post_status’ … Read more

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