Show only posts from one category on custom post type archive page

Use the pre_get_posts action to modify any main query before it is sent to the database, this includes the case of your home page as well. Calling query_posts in the template runs a new query, overwriting the original- it’s a waste of resources and can produce unpredictable results, particularly with pagination. function wpa_pre_get_posts( $query ){ … Read more

Custom Post Type permalink shows wrong page: homepage/index.php

post_type needs to be max. 20 characters, can not contain capital letters or spaces, in register_post_type(); function your post type name is capitalize Portfolio replace with lower letters portfolio this is my register post type snippet, follow it // add action register our post type portfolio add_action( ‘init’, ‘register_cpt_portfolio’ ); // Register our Custom Post … Read more

Use menus with anchors

Got it — needed to use a walker function. I used a slightly modified version of the one in this tutorial The main thing I modified was changing $attributes .= ! empty( $item->url ) ? ‘ href=”‘ . esc_attr( $item->url) .'”‘ : ”; to $attributes .= ‘ href=”#’ . esc_attr( basename(get_permalink()) ) .'”‘ ; but … Read more

Turn on and off custom post type from admin?

Yes, custom post types are registered on the fly, on every request. So you can create an option, say active_custom_post_types and check for that before you register the post type. Pseudo-code: $possible_cpts = array( ‘book’, ‘portfolio’ ); $active_cpts = get_option( ‘active_custom_post_types’ ); if ( ! empty ( $active_cpts ) && is_array( $active_cpts ) ) { … Read more