19

A faster solution is: $post = array( 'ID' => $post_id, 'post_status' => $status ); wp_update_post($post); This way you don't have to get the post.


13

register_post_status is used for creating a custom post status. The protected argument, if true, specifies that a user must be logged in and have edit permissions on the post to view (preview) it. For example, you said that the "draft" post status has protected set to true. This means that you can only view (preview) the draft post if you have permission ...


12

There is simple way, how to get all posts with any status: $articles = get_posts( array( 'numberposts' => -1, 'post_status' => 'any', 'post_type' => get_post_types('', 'names'), ) ); Now you can iterate throughout all posts: foreach ($articles as $article) { echo $article->ID . PHP_EOL; //... }


12

I guess it should work . As long as $id is available things are easy. <?php if (empty($items)) { $ret .= " 'No new videos.'"; $postid = $post->ID; //Supply post-Id here $post->ID. wp_update_post(array( 'ID' => $postid, 'post_status' => 'draft' )); } else foreach ( $items as $item ) : ?> Give it a ...


11

You can use 'publish' === get_post_status( $id ), where $id could be the current page ID retrieved via get_the_ID() or any other.


10

There is a great Step by Step description on how to do that here http://jamescollings.co.uk/blog/wordpress-create-custom-post-status/ To add your custom post status to the drop-down menue, just add the following to your themes function script: add_action('admin_footer-post.php', 'jc_append_post_status_list'); function jc_append_post_status_list(){ global $...


9

This solves my problem: register_post_status('my_custom_post_status', array( 'label' => __('The Label', 'domain'), 'public' => !is_admin(), 'exclude_from_search' => true, 'show_in_admin_all_list' => false, 'label_count' => //blablabla )); !is_admin() makes the status only public on the frontpage. If you find a better ...


8

Your code should be sound, and should add the desired status to the $wp_post_statuses global array. If you are expecting it to show up in the admin drop-down, however, this is an ongoing issue: https://core.trac.wordpress.org/ticket/12706


8

You need to set the who parameter in get_users <?php $blogusers = get_users( 'orderby=post_count&who=authors' ); foreach ( $blogusers as $user ) { echo '<li>' . esc_html( $user->display_name ) . '</li>'; } ?> EDIT Seems I was to fast answering. The code in your question and in my answer is the start to what you ...


6

The WP_Query class method ->query() accepts an any argument for post_status. See wp_get_associated_nav_menu_items() for a proof. The same goes for get_posts() (which is just a wrapper for above call).


6

In most cases you can use get_posts() with 'any' parameter for this: $posts = get_posts( array( 'numberposts' => -1, 'post_status' => 'any', 'post_type' => 'my-post-type', ) ); But this way you won't get posts with status trash and auto-draft. You need to provide them explicitly, like this: $posts = get_posts( array( 'numberposts' =>...


6

Preface Once post preview is frontend, the comment form depends on how theme handle it. I will assume in this answer that the comment form is shown using the standard comment_form() function. The previous assumption isn't enough, in fact comment_form is probably the function in WordPress core with more hooks. There is almost an hook for every line. So what ...


6

There is no default way in WordPress to do this task, as Pieter Goosen pointed out, exists the argument who for get_users() that returns users that can post, not the users that have posted. However, you can use 'pre_user_query' to add a JOIN SQL clause to only get users that have at least one post. To be honest, when you query users ordering them by post ...


6

To check post with post status private, you could run the following: if (get_post_status() == 'private' && is_user_logged_in()) { // it's private and user is logged in, do stuff } elseif (get_post_status() == 'draft') { // it's draft, do stuff } else { // it's something else, do stuff } Or, in your current setup, you can simply only ...


5

You can create your custom button in a function and hook it into post_submitbox_misc_actions and this will add it right above the publish button. To change the status use wp_update_post in an Ajax function. Give it a try and post back with your code if you run into any problems. UPDATE: add_action('post_submitbox_misc_actions', '...


5

Hook wp_insert_post_data filter to force a post status to be set as incomplete before it can be set as published. With the following code only a post that is set as incomplete can be saved: add_filter( 'wp_insert_post_data', 'prevent_post_change', 20, 2 ); function prevent_post_change( $data, $postarr ) { if ( ! isset($postarr['ID']) || ! $postarr['ID']...


5

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 ),...


5

This largely depends on where within the boot/request sequence you decide to make an attempt at retrieving statuses and it also depends on whether someone, thing, plugin or theme is doing something, funky, or not but the latter is less likely the case. Useful API functions: get_post_statuses docs | source Retrieves statuses for the built in post type of ...


4

That's because the fields weren't set then. Note: The »Autosave« process/request also doesn't save them. Use the values from $_POST instead for your "new_to_publish" action. EDIT: Do NOT forget to escape and properly sanitize input data! Else you will open a security hole.


4

I was investigating the issue for this question, and one option is using the plugin Edit Flow. It can be configured to display custom post_status in specific CPT's, but further tests are necessary to see if it applies to this case. Other option is using toscho's Retranslate plugin, where you can define the string to be translated and the post_type: https://...


4

You probably have some custom functions in your themes functions.php Add a return; on top of this file. If the problem is solved: Move it below the first function. Proceed this way until you've found the function that is causing the problem. If this doesn't work: Go and do the same for one template file after each other until you found the file that is ...


4

In that case your error lays with wp-ecommerce itself as you've ruled out any via process of elimination. The last thing I would suggest you do, is switch from your current theme to the default WordPress theme (still ensuring that all plugins except wp-ecommerce are disabled) and if the problem still persists then its definitely wp-ecommerce. We can ...


4

The problem is explained in the quote you've mentioned: "Default value is 'publish', but if the user is logged in, 'private' is added. And if the query is run in an admin context, protected statuses are added too. By default protected statuses are 'future', 'draft' and 'pending'." Ajax call is always considered to be from an admin context.


4

WP_Query has a bug (#29167) when you try to fetch posts with (almost?) any other status than publish. This bug seems to be fixed in trunk. I haven’t tested it, so I cannot tell if it covers your use case. Try it, and give feedback there if it doesn’t. There are two workarounds: Use get_post( $post_id ). This runs its own query and isn’t affected by this ...


3

Every time you edit a post/page, WordPress creates timely revisions of it. Check the Firebug console for the requests that are sent at regular intervals when you are on the edit page. They are useful if you lose the post content at some point and want to get back to an earlier version of the post. Once you publish the final version of the post then you can ...


3

You get the full post object as a second parameter on save_post. Use it to change the status just like the following code. add_action( 'save_post', 'wpse_78351_status', 10, 2 ); function wpse_78351_status( $post_ID, $post ) { remove_filter( current_filter(), __FUNCTION__ ); if ( 'trash' !== $post->post_status ) //adjust the condition { ...


3

I would filter pre_get_posts. function allow_pending_posts_wpse_103938($qry) { if (!is_admin() && current_user_can('edit_posts')) { $qry->set('post_status', array('publish','pending')); } } add_action('pre_get_posts','allow_pending_posts_wpse_103938'); That should show pending posts to your editors for all of your queries on the front ...


3

Use the IN operator for arrays. When using $wpdb->prepare() you don't have to use quotes around the string placeholder %s. The string placeholder will be quoted automatically. That's also the reason why you have to take precautions when using $wpdb->prepare() with the IN operator if the array values are strings. This first example doesn't use the ...


3

I wonder if you could use something as simple as this: (similar to the suggestion of @ialocin) /** * Use the "Force" on the post status ;-) */ add_action( 'wp_insert_post_data', function( $data, $postarr ){ $change_post_status = array( 'draft', 'private' ); // Edit to your needs if( 'cpt' === $data['post_type'] && in_array( $...


3

Since version 4.3.0, you can now specify the parameter has_published_posts to the get_users(); function call. Pass an array of post types to filter results to users who have published posts in those post types. true is an alias for all public post types. Example if ( $users = get_users( array( 'orderby' => 'nicename', 'order' ...


Only top voted, non community-wiki answers of a minimum length are eligible