Articles of publish

Can we have private drafts?

As per the documentation, Draft and Private are two mutually exclusive post statuses. Therefore, when you mark a draft post as Private, it is no longer a draft. We are a big team making extensive use of private posts. Therefore, we would like to mark a draft as private (an unfinished post that will be […]

Modify front-end delete button to publish pending posts

I’ve found this helpful snippet to make a delete post link on the front-end: <?php if (current_user_can(‘edit_post’, $post->ID)) echo “<a href='” . wp_nonce_url(“/wp-admin/post.php?action=delete&amp;post=$id”, ‘delete-post_’ . $post->ID) . “‘>Delete</a>” ?> What I am wondering if there is a way to modify this code and create a complementary Publish link, which would publish a pending post, from […]

How to change post status in hook?

I have similar problem as described in How to trap "Publish" button to check for meta box validation? Answer there is to hook into save_post and change post type. How can I do it? I try to use wp_transition_post_status but it doesn’t work for me… function myHook( $post_ID, $post ) { wp_transition_post_status(‘pending’, $post->post_status, $post ); […]

Show recent published posts

I want to list recent published posts of my wp blog and exclude certain posts of some categories. The following code works fine, 10 recent posts are listed and posts in the listed categories are ignored. However, draft posts are listed as well. $args = array( ‘numberposts’ => ’10’, ‘tax_query’ => array( ‘post_type’ => ‘post’, […]

Elegant way to include only published posts with get_objects_in_term()?

The obvious way is to iterate through the resulting array of IDs, get_post for each and test against post_status == ‘publish’. But I wonder whether this could cause memory issues since get_post will attempt by default to cache each result? Short of a custom SQL join, are there any surprise args one can pass to […]

Can I set a timer for pages to be published?

I have a page that’s in draft mode right now because I want to publish this on a particular day (sometime this week). Is there a way that I can set a timer/countdown for this page to automatically be published on a day that I choose? I don’t want to manually publish this page as […]

How can I automatically set a post slug based on the post title during post publish?

When you create a post in WP, if you don’t specify a title rapidly, WP generates a default slug on autosave, based on the post ID. Then, when you add the title later, unless you modify the slug by editing it, it remains the same (based on post ID) What I’m trying to do is […]

How to trap “Publish” button to check for meta box validation?

I’m trying to do some form validation on my custom meta box, and I remember somewhere reading about some javascript function to disable/enable the Publish button – except I can’t find it. How do I either a) enable/disable the publish button or, b) when Publish is clicked, trap it and prevent the update and alert […]

wp_publish_post breaks permalinks

I’m creating a system, where some custom post drafts are being prepared, and after certain actions taken by moderators it is being automatically published. So, first I create post draft like that: $newpost = array( ‘post_title’ => ‘Raport ‘.date(“Y-m-d”), ‘post_content’ => ‘Add your content here’, ‘post_type’ => ‘raport’, ‘post_status’ => ‘draft’, ‘post_author’ => $userid ); […]

Add javascript when post is published

I am trying to add javascript when a post has been published so that it’s more noticable for my user but I can’t figure out what to use. I tryed with publish_post and save_post, but it doesn’t work unless I put die; at the end of the code. I’ve tryed so hard to stay out […]