Custom Post Types – Taxonomy and Customization

You need to add a taxonomies argument to your registration array: ‘taxonomies’ => array(‘category’) That is: array( ‘labels’ => array( ‘name’ => __( ‘Products’ ), ‘singular_name’ => __( ‘Product’ ), ‘add_new_item’ => __(‘Add New Product’), ‘edit_item’ => __(‘Edit Product’), ‘search_items’ => __(‘Search Products’) ), ‘public’ => true, ‘has_archive’ => true, ‘rewrite’ => array(‘slug’ => ‘products’), … Read more

Display only a single CPT

You must ensure that the post type is registered with has_archive property set to true Look at codex example, replace ‘Books’ with ‘Products’ function codex_custom_init() { $labels = array( ‘name’ => ‘Books’, ‘singular_name’ => ‘Book’, ‘add_new’ => ‘Add New’, ‘add_new_item’ => ‘Add New Book’, ‘edit_item’ => ‘Edit Book’, ‘new_item’ => ‘New Book’, ‘all_items’ => ‘All … Read more

pre_get_posts works in post type archive but not in single post

The next_post_link() and previous_post_link() functions do not use the same query that ‘pre_get_posts’ affects. They use their own custom queries. You have to use other filters to affect them. Utimately, the get_adjacent_post() function does the bulk of the work for the next_post_link() and previous_post_link() functions. Here is part of that function: $adjacent = $previous ? … Read more

I can’t connect my custom jquery to wp admin

Because YOU CAN’T DEREGISTER JQUERY IN THE ADMIN Why would you even want to? See src: http://core.trac.wordpress.org/browser/tags/3.6/wp-includes/functions.wp-scripts.php?order=name#L105 // Do not allow accidental or negligent deregistering of critical scripts in the admin. Show minimal remorse if the correct hook is used. if ( is_admin() && ‘admin_enqueue_scripts’ !== current_filter() ) { $no = array( ‘jquery’, ‘jquery-core’, ‘jquery-migrate’, … Read more

Filter posts by specific custom category and current tag

There is a descriptively named argument to WP_Query, which is what you should be using, called post__not_in which excludes any post IDs passed into it. Also, the {tax} => {term_name} pattern that you have used twice is deprecated. You should be using a tax_query argument instead. Lines like this one, strip_tags( get_the_term_list( $wp_query->post->ID, ‘buyers-club’ ) … Read more

Easier way to display custom post meta?

In situations like this sometimes it’s easier to get all the data up front and then build the output. First get the link and rating, then check if the link is empty. If the link isn’t empty append it to the rating. Lastly, print the rating to the page. <?php $review_link = esc_html( get_post_meta( get_the_ID(), … Read more

Why does my URL keep returning 404 error code?

Here is the solution of my problem, thanks to @Milo: function wpa_date_archive_post_types( $query ){ if( $query->is_main_query() && $query->is_date() ): $query->set( ‘post_type’ , array( ‘movie’ ) ); $query->set( ‘year’ , 0 ); $query->set( ‘tag’ , ‘1994’ ); $query->set( ‘post_status’ , array( ‘publish’ ) ); endif; } add_action( ‘pre_get_posts’, ‘wpa_date_archive_post_types’ );