Flush rewrite rules when new cpt is registred

Post types are registered on every load. They’re not stored in the database or some other sort of persistent storage. The posts are, but not the post types. So the correct place to flush rewrite rules is when the theme is activated. This can be done with the after_switch_theme hook: add_action( ‘after_switch_theme’, ‘flush_rewrite_rules’ ); For … Read more

Duplicate posts in my custom loop

You’re trying to loop through the thumbnail, which doesn’t make any sense: foreach ($thumbnail as $thumb){ And then inside the loop you’re referring to $thumbnail again anyway: <img class=”thumbnail zoom” src=”https://wordpress.stackexchange.com/questions/280435/<?php echo $thumbnail[0];?>” > wp_get_attachment_image_src() returns an array that looks like this: array( 0 => ‘http://website.com/path/to/image.jpg’, // URL 1 => 150, // Width 2 => … Read more

Get posts under custom taxonomy and custom post type

You will need to use this code: $the_query = new WP_Query( array( ‘post_type’ => ‘courses’, ‘tax_query’ => array( array ( ‘taxonomy’ => ‘courses_category’, ‘field’ => ‘slug’, ‘terms’ => ‘yourterm’ ) ), ) ); while ( $the_query->have_posts() ) : $the_query->the_post(); // Show Posts … endwhile; You can convert this in shortcode and just append it on … Read more