Hot answers tagged

16

This works for me: add_filter('page_attributes_dropdown_pages_args', 'my_attributes_dropdown_pages_args', 1, 1); function my_attributes_dropdown_pages_args($dropdown_args) { $dropdown_args['post_status'] = array('publish','draft'); return $dropdown_args; }


11

I just stumbled across this question and thought I'd share my most common solution which may not work for everyone in all scenarios but I believe this is the most efficient way to achieve the desired results. When you register a CPT that does not require a single-view output in your theme or plugin, simply define the property 'public' => false, For ...


10

You can accomplish the above using hooks. Use the code below in your active theme's functions.php file to get this work delete permalink under wordpress post title add_filter( 'get_sample_permalink_html', 'wpse_125800_sample_permalink' ); function wpse_125800_sample_permalink( $return ) { $return = ''; return $return; } Customizing post link ...


8

Here is a very rough block of code that should get you started. What it does is look for the most recent "future" or "publish" post and if that value is less than 1 hour different from the latest scheduled post, it schedules the current post to one hour plus the "most recent" time found. function force_time_between_posts_wpse_104677($data, $postarr) { ...


8

Although the name of the function wp_publish_post() suggests that it can be used to publish a post it should obviously not be used to publish a draft post programmatically. The way to do so is to use wp_update_post() and set the post status manually to publish: <?php // Update post with the ID 42 $postData = [ 'ID' => 42, 'post_status' => '...


7

Draft previews Take a quick look at this chunk of core code in query.php which [Checks] post status to determine if post should be displayed. http://core.trac.wordpress.org/browser/tags/3.3.1/wp-includes/query.php#L2658 if ( ! is_user_logged_in() ) { // User must be logged in to view unpublished posts. $this->posts = array(); } ...is what ...


7

First of all you have to understand that when we update a post, wp_update_post function is called. But due to a bit not optimal design of WP core, the actual saving is processed by wp_insert_post function. See it in trac on line 3006. Ok, next lets see what is inside of wp_insert_post function. As you can see, on line 2950, save_post action is called each ...


7

publish_post will give you a second parameter if you ask for it. Notice the fourth parameter of the add_action call. That is your post object. function run_on_publish_wpse_100421( $postid, $post ) { if ('news' == $post->post_type) // your code } } add_action('publish_post','run_on_publish_wpse_100421',1,2);


5

Checking if meta values exist You can use get_posts() (or the WP_Query object) to query all posts which match the post meta you want to save. You will need to specify the post status (i.e. which statuses are you willing to ignore). Below is the untested code to this. (For completeness I've left in arguments which could be omitted because they are given ...


5

The {$old_status}_to_{$new_status} and {$new_status}_{$post->post_type} hooks tend to generally solve the problem. To avoid running the code in case post status is changed to draft then published again (after already being published), implement a simple flag using the post_meta functionality. Note: the updated hook should be 'draft_to_publish' instead ...


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


4

The has_post_thumbnail() works for me, in WP versions 3.4.1 and other most recently. But in this logic, because the WP will publish the post even with exit or wp_die() or anything to terminate the PHP script. For prevent that the post stay with published status, you will need to update the post before terminate. Look the code below: add_action('save_post', '...


4

Is there any plugin I can use for this task? No. But there is a tool you can use. A colleague of mine was facing an identical situation. Multiple authors on one site wanted to cross post from the central, multi-author blog onto their own blogs. The solution was for them to use an external blog editing tool. If you're on Windows, there's a tool called ...


4

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('...


4

Solved it! Used save_post to run push_notification() as well as to run the function save_post_meta() that saves my post meta. The problem occurred coz push_notification() gets fired before save_post_meta() due to which the meta wasn't being saved and therefore it remained inaccessible. Just changed priorities of the functions to make it work like so : ...


4

You need a function that hook into post status transitions and send and email containing a link with some verification variables and a function that takes that variables, check them and if all ok update posts status. Following code I think is self-explanatory, and comments give additional help: add_action('new_to_pending', 'send_approve_link'); add_action('...


4

You need to write your hook for transition_post_status action: function authorNotification( $new_status, $old_status, $post ) { if ( $new_status == 'publish' && $old_status != 'publish' ) { $author = get_userdata($post->post_author); $message = " Hi ".$author->display_name.", New post, ".$post->...


4

The post gets added and published but since you have the meta query and the meta key is not added when you submit the post from frontend, it does not show up. Use the following code which adds the meta data as needed. if ( isset( $_POST['submitted'] ) ) { $post_information = array( 'post_title' => wp_strip_all_tags( $...


4

I wouldn't use that hook. Here's why Try something like this using admin_notices. function wpsites_admin_notice() { $screen = get_current_screen(); if( 'post' == $screen->post_type && 'edit' == $screen->base ){ ?> <div class="error"> <p><?php _e( 'Updated Demo Message!', 'wpsites' ); ?></p> </div> <?...


4

The following query retrieves the oldest post of a specified user/author: $user_id = 42; // or whatever it is $args = array( 'posts_per_page' => 1, 'post_status' => 'publish', 'author' => $user_id, 'orderby' => 'date', 'order' => 'ASC', ); $first_post = new WP_Query($args); if ($first_post->have_posts()) { $...


3

There's not a good way to do this as the code for this section is pretty rigid. You can simply remove the elements via JavaScript. By removing (and not just hiding) the elements, you disable the functionality. You can customize the following to your needs I'm sure. Use CSS to hide the post actions inner box so the prohibited buttons never display to the ...


3

This might work: $date = get_the_date(); $date_unix = strtotime($date); // now lets add 100 years $date_unix += (100*365*24*60*60); $echo date('U',$date_unix); The main issue this faces is that there may be a cut off/rollover around 2030~ depending on your system. In those cases, print out the current date, but without the year, then manually print the ...


3

I had the same issue as you when I was dealing with events and wanted to show future events. Here is what I coded: add_action( 'init', 'change_future_posts_to_post_now' ); function change_future_posts_to_post_now() { remove_action("future_post", '_future_post_hook'); add_action("future_post", 'publish_future_posts_now', 2, 10); } function ...


3

What exactly do you mean with "published"? One thing you can try is this : http://planetozh.com/blog/my-projects/wordpress-hooks-filter-flow/ The script runs in your WordPress root (or in /wp-admin/ if you prefer) and enumerates filters that are loaded in your blog. Hooks are displayed alphabetically, and for each hook, active filters (or actions, they’...


3

I know this is an old post, but I just cleaned up the code if anyone finds this thread via search like I did. function change_publish_button( $translation, $text ) { if ( 'CUSTOM_POST_TYPE' == get_post_type() && ($text == 'Publish' || $text == 'Update') ) { return 'Save'; } else { return $translation; } }


3

Fairly simple using jQuery and global $typenow ex: add_action('admin_print_scripts-post.php', 'my_publish_admin_hook'); add_action('admin_print_scripts-post-new.php', 'my_publish_admin_hook'); function my_publish_admin_hook(){ global $typenow; if (in_array($typenow, array('post','page','mm_photo '))){ ?> <script language="...


3

You seem to be concerned only with new posts (as previously-created posts will have the postmeta attached and available when transitions are run), and want to do push_notification on newly-created posts only if a certain postmeta value is present. Correct? Create your own hook in the function that saves your postmeta, after all of your update_postmeta calls,...


3

Solution based in this StackOverflow Q&A. Well, more a proof of concept than anything... Style and scripts being printed the lazy way. Add a fixed Scroll to top div linked to an anchor near the Publish button. add_action( 'admin_head-post.php', 'scroll_to_top' ); function scroll_to_top() { ?> <style>#box { /* Position ...


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

You can hook into the post footer actions (based on this answer, not tested): add_action( 'admin_footer-post-new.php', 'wpse_80215_script' ); add_action( 'admin_footer-post.php', 'wpse_80215_script' ); function wpse_80215_script() { if ( 'post' !== $GLOBALS['post_type'] ) return; ?> <script> document.getElementById("publish")....


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