Note that there are some explanatory texts on larger screens.

plurals
  1. POExclude Category from Custom Post Type Loop / Archive
    primarykey
    data
    text
    <p>I've been reading through posts on how to do this but none seem to make sense or work. I have created a custom post type (research) in my functions.php file and a custom taxonomy (classifications). I also have a custom archive page (archive-research.php) for my post type.</p> <p>I have a category (classification) called "oldresearch" that I would like to exclude from the custom archive template.</p> <p>Below is my custom post type code. Could someone please help me and let me know where the exclusion code needs to go.</p> <pre><code>&lt;?php /* redirect users to front page after login */ function redirect_to_front_page() { global $redirect_to; if (!isset($_GET['redirect_to'])) { $redirect_to = get_option('siteurl'); } } add_action('login_form', 'redirect_to_front_page'); if ( function_exists('register_sidebars') ) register_sidebars(3); add_action('init', 'register_custom_menu'); function register_custom_menu() { register_nav_menu('custom_menu', __('Custom Menu')); } /** Registering Custom Post Type: Research **/ // Register Taxonomy for Research $labels = array( 'name' =&gt; 'Classifications', 'singular_name' =&gt; 'Classification', 'search_items' =&gt; 'Search Classifications', 'popular_items' =&gt; 'Popular Classifications', 'all_items' =&gt; 'All Classifications', 'parent_item' =&gt; 'Parent Classifications', 'edit_item' =&gt; 'Edit Classifications', 'update_item' =&gt; 'Update Classifications', 'add_new_item' =&gt; 'Add New Classification', 'new_item_name' =&gt; 'New Classifications', 'separate_items_with_commas' =&gt; 'Separate Classifications with commas', 'add_or_remove_items' =&gt; 'Add or remove Classifications', 'choose_from_most_used' =&gt; 'Choose from most used Classifications' ); $args = array( 'label' =&gt; 'Classifications', 'labels' =&gt; $labels, 'public' =&gt; true, 'hierarchical' =&gt; true, 'show_ui' =&gt; true, 'show_in_nav_menus' =&gt; true, 'args' =&gt; array( 'orderby' =&gt; 'term_order' ), 'rewrite' =&gt; array( 'slug' =&gt; 'research/classifications', 'with_front' =&gt; false ), 'query_var' =&gt; true ); register_taxonomy( 'Classifications', 'Research', $args ); // Register Classification Column add_filter( 'manage_research_posts_columns', 'ilc_cpt_columns' ); add_action('manage_research_posts_custom_column', 'ilc_cpt_custom_column', 10, 2); function ilc_cpt_columns($defaults) { $defaults['Classifications'] = 'Classifications'; return $defaults; } function ilc_cpt_custom_column($column_name, $post_id) { $taxonomy = $column_name; $post_type = get_post_type($post_id); $terms = get_the_terms($post_id, $taxonomy); if ( !empty($terms) ) { foreach ( $terms as $term ) $post_terms[] = "&lt;a href='edit.php?post_type={$post_type}&amp;{$taxonomy}={$term-&gt;slug}'&gt; " . esc_html(sanitize_term_field('name', $term-&gt;name, $term-&gt;term_id, $taxonomy, 'edit')) . "&lt;/a&gt;"; echo join( ', ', $post_terms ); } else echo '&lt;i&gt;No terms.&lt;/i&gt;'; } // Register Custom Post Type function research_post_type() { $labels = array( 'name' =&gt; _x( 'Research', 'Post Type General Name', 'text_domain' ), 'singular_name' =&gt; _x( 'Research', 'Post Type Singular Name', 'text_domain' ), 'menu_name' =&gt; __( 'Research', 'text_domain' ), 'parent_item_colon' =&gt; __( 'Parent Research', 'text_domain' ), 'all_items' =&gt; __( 'All Research', 'text_domain' ), 'view_item' =&gt; __( 'View Research', 'text_domain' ), 'add_new_item' =&gt; __( 'Add New Research', 'text_domain' ), 'add_new' =&gt; __( 'New Research', 'text_domain' ), 'edit_item' =&gt; __( 'Edit Research', 'text_domain' ), 'update_item' =&gt; __( 'Update Research', 'text_domain' ), 'search_items' =&gt; __( 'Search Research', 'text_domain' ), 'not_found' =&gt; __( 'No Research found', 'text_domain' ), 'not_found_in_trash' =&gt; __( 'No Research found in Trash', 'text_domain' ), ); $rewrite = array( 'slug' =&gt; 'research', 'with_front' =&gt; true, 'rewrite_pages' =&gt; true, 'rewrite_feeds' =&gt; true, ); $args = array( 'label' =&gt; __( 'research', 'text_domain' ), 'description' =&gt; __( 'Agri-Gro product research', 'text_domain' ), 'labels' =&gt; $labels, 'supports' =&gt; array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'trackbacks', 'revisions', 'custom-fields', 'page-attributes', 'post-formats', ), 'taxonomies' =&gt; array( 'Classifications', 'post_tag' ), 'hierarchical' =&gt; true, 'public' =&gt; true, 'show_ui' =&gt; true, 'show_in_menu' =&gt; true, 'show_in_nav_menus' =&gt; true, 'show_in_admin_bar' =&gt; true, 'menu_position' =&gt; 20, 'menu_icon' =&gt; 'http://www.agrigro.com/news/wp-content/uploads/2013/01/Documents-icon.png', 'can_export' =&gt; true, 'has_archive' =&gt; true, 'exclude_from_search' =&gt; false, 'publicly_queryable' =&gt; true, 'rewrite' =&gt; $rewrite, 'capability_type' =&gt; 'page', ); register_post_type( 'research', $args ); } // Hook into the 'init' action add_action( 'init', 'research_post_type', 0 ); ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload