Hide admin bar on certain post type

Don’t hack your WordPress core. It’s overriden after every upgrade (plugins do exist for some reason). You can solve your problem in this way: 1) Open your single.php. 2) Define <?php function hideAdminBar ($post_id) { if (get_post_type ($post_id) == ‘post’) { add_filter (‘show_admin_bar’, ‘__return_false’); /* For removing the top blank space. */ echo ‘<style type=”text/css” … Read more

Favouriting a Custom Post Type

You should not be using element IDs more than once, instead you should be using classes. Without going into to much detail try the adjustments below… Change the following: <a href=”#add-to-favorite” id=”add-to-favorite”> <i class=”fa fa-star-o”></i>&nbsp; <span class=”add-to”>Add to Favourites</span> </a> …to <a href=”#add-to-favorite” class=”add-to-favorite”> <i class=”fa fa-star-o”></i>&nbsp; <span class=”add-to”>Add to Favourites</span> </a> Change your JS … Read more

WP_Query orderby custom field then post_date in one query

Multiple meta_query arguments with OR You may use the ‘relation’ => ‘OR’ argument in meta_query with two sets of field_order arguments: one with meta_value >= ‘0’ and the other one with NOT EXISTS to generate the main query. ‘meta_query’ => array( ‘relation’ => ‘OR’, field_order’ => array( ‘key’ => ‘field_order’, ‘value’ => ‘0’, ‘compare’ => … Read more

register_post_type & ‘register_meta_box_cb’ argument

I love answering my own questions: Wrap the function add_additional_input_field() in a new function that contains this and call it in the register_meta_box_cb argument. And yes: This is the solution. Example: <? /** Plugin Name: (WPSE) #6345 Example MetaBox plugin */ add_filter( ‘plugins_loaded’, function() { register_post_type( ‘book’, [ ‘register_meta_box_cb’ => function() { printf( ‘<label>Length:</label>’ .'<input … Read more

How do I filter the excerpt metabox description in admin?

This description is generated by post_excerpt_meta_box() function and is not passed through any explicit filters. It is however echoed by translation-related _e() function and so passes through gettext filter (which from your question you are already familiar with). As for limiting it to your CPT, I think current post type in admin is held in … Read more

How to order adjacent posts (prev / next) by custom field value?

You can filter SQL to change to your condition in get_adjacent_post() ( source ) : $sort = apply_filters( “get_{$adjacent}_post_sort”, “ORDER BY p.post_date $order LIMIT 1” ); Or filter link altogether in adjacent_post_link() ( source ) : echo apply_filters( “{$adjacent}_post_link”, $format, $link ); PS $adjacent can be next or previous.

Action hook on Edit custom post type?

register_post_type() has a registration option called ‘register_meta_box_cb’. Set that to a valid callback and it will call that function only when it is compiling the meta boxes for that post type’s edit screen. Something like this: register_post_type( ‘foo’, array( ‘public’ => true, ‘label’ => ‘foo’, ‘register_meta_box_cb’ => ‘bar’, )); function bar(){ add_meta_box(‘blah’, ‘blah’, /* etc … Read more

how to group custom post types

The filter Inside /wp-admin/menu.php, you’ll find this filter at the end of the “add css classes”-loop: apply_filters( ‘add_menu_classes’, $menu ) The function The following code attaches the right classes to the first and previous elements. It also adds the separator in between. If you need to add another separator to the end/after your group, you’ll … Read more