Disable adding of new post (custom post type)

As per this answer, the “correct way” is: register_post_type( ‘custom_post_type_name’, array( ‘capability_type’ => ‘post’, ‘capabilities’ => array( ‘create_posts’ => false, // Removes support for the “Add New” function ( use ‘do_not_allow’ instead of false for multisite set ups ) ), ‘map_meta_cap’ => true, // Set to `false`, if users are not allowed to edit/delete existing … Read more

Undefined index: at_nonce in custom post metabox

These are your problem lines: if ( $_POST && !wp_verify_nonce($_POST[‘at_nonce’], __FILE__) ) { return; } You check to see that $_POST is set, but you don’t check $_POST[‘at_nonce’]. If $_POST is set but that key is not then you will get a Notice. It is a simple fix: if ( isset($_POST[‘at_nonce’]) && !wp_verify_nonce($_POST[‘at_nonce’], __FILE__) ) … Read more

How to add a link(href) so when i click it, it renders (shows all) posts of custom post type (rich_media), from the current category?

function add_post_type_to_archives($query) { if(is_archive() and empty($query->query_vars[‘suppress_filters’])){ $query->set(‘post_type’, array(‘post’, ‘rich_media’)); } return $query; } add_filter(‘pre_get_posts’, ‘add_post_type_to_archives’); For a custom post type to be shown in archives, it needs to be added to the $query. Like above. It’s up to you to refine the situations where you want it added. Like: if(!empty($query->query_vars[‘custom_tag_query_var’])){ $query->set(‘post_type’, array(‘post’, ‘rich_media’)); } This … Read more

Using new WP_Query in shortcode in a custom field causes the main post content to not display

You’re using get_posts which returns an array of posts, which you can loop through using foreach, but not the_loop. Try this version of the code: function ia_news_display_test($atts){ // [ia_news cat=”category” num=’numbertodisplay’] extract(shortcode_atts(array( ‘cat’ => ‘any’, ‘num’ => ‘2’, ), $atts)); $dirloop = new WP_Query( array( ‘post_type’ => ‘ia_news’, ‘category_name’ => $cat, ‘posts_per_page’ => $num, ‘orderby’ … Read more

Include custom post type in “all posts”

Filter pre_get_posts: add_filter( ‘pre_get_posts’, ‘wpse_98213_add_post_types_to_tax_query’ ); /** * Let WP search for custom post types on taxonomy archives. * * @wp-hook pre_get_posts * @param object $query * @return object */ function wpse_98213_add_post_types_to_tax_query( $query ) { if ( ! is_main_query() or ! is_tax( ‘your_taxonomy_name’ ) ) return $query; $query->set( ‘post_type’, array ( ‘portfolio’, ‘post’ ) ); … Read more