Hot answers tagged

14

You can simply hide the options using CSS. This will add a display:none style to the misc and minor publishing actions on the post.php and post-new.php pages. It checks for a specific post type as well since all post types use these two files. function hide_publishing_actions(){ $my_post_type = 'POST_TYPE'; global $post; if($post->...


14

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


9

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

Not mine but modified from here. But if you pop this into functions.php or a plugin it will work. add_filter( 'gettext', 'change_publish_button', 10, 2 ); function change_publish_button( $translation, $text ) { if ( 'yourcustomposttype' == get_post_type()) if ( $text == 'Publish' ) return 'Save'; return $translation; }


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);


7

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


7

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


6

Just call p2p_connect( $id_of_post_type_a, $id_of_post_type_b ); in the form handling code.


5

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


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

I'm using jQuery Tools Validator $("#publish").click(function(event){ //validating var inputs = $(".TTWForm-container :input").validator(); //check if not valid stop loading ajax icons if( ! inputs.data("validator").checkValidity()){ event.stopImmediatePropagation(); } } This code fires once the ...


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

There isn't, by default, a 'publish' link because of the way WordPress handles publishing posts. 'publish' is not consider an action in the same way 'delete' is, instead you save the post, with all its data, including its post status. To get round this you can create your own action handler. In order to avoid potential clashes with WP or other plug-ins, ...


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

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

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

from the plugin; uses action 'post_submitbox_misc_actions' and some query to catch the user Publish form: http://wordpress.org/extend/plugins/private-post-by-default/ function default_post_visibility(){ global $post; if ( 'publish' == $post->post_status ) { $visibility = 'public'; $visibility_trans = __('Public'); } elseif ( !empty( $post->...


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 can add 'post_status' => 'publish' in your query to retrieve only objects with status publish , this will work for get_posts, query_posts or $wp_query and to include also custom taxonomies you can use tax_query in your args list


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’...


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