Custom Post Types and Broken Permalinks

You need to flush rewrite rules on plugin activation for your custom post type to begin working. register_deactivation_hook( __FILE__, ‘flush_rewrite_rules’ ); register_activation_hook( __FILE__, ‘myplugin_flush_rewrites’ ); function myplugin_flush_rewrites() { // call your CPT registration function here // (it should also be hooked into ‘init’) dwwp_register_post_type(); flush_rewrite_rules(); } You may have noticed it randomly working without having … Read more

Prevent Archive URLs

WordPress generates date archives automatically, it’s just a thing it does. You see the index.php template probably because there isn’t a more specific one for date archives in your current theme. There are plugins that disable these archives, Yoast SEO is one. A quick fix is to empty the date archive rewrite rules: add_filter( ‘date_rewrite_rules’, … Read more

How to make a page show posts only from specific categories without editing php files

You can use WP_Query to lists posts with excerpt from specific category. Here is sample code: <?php $args = array( ‘posts_per_page’ => -1, ‘cat’ => 7, ‘orderby’ => ‘post_date’, ‘order’ => ‘DESC’, ‘post_type’ => ‘post’, ‘post_status’ => array(‘publish’, ‘draft’, ‘pending’ ), ‘author’ => 1, ); $postslist = get_posts( $args ); foreach ( $postslist as $post … Read more

Fill the exclude array() in get_posts()

After three days of struggling and posting a question here I managed to find an answer. Yeh I know… To my defense I can say that it’s my first WP project. I did it this way: $exclude = get_excluded_parents(); $parents = get_posts( array( ‘post_type’ => ‘jhk_story’, ‘orderby’ => ‘ID’, ‘order’ => ‘ASC’, ‘numberposts’ => -1, … Read more