How to show list of taxonomy terms associated with specific post?

I used following codes and it is working perfectly. <?php $terms = wp_get_post_terms($post->ID, ‘competition’); ?> <?php $count = count($terms); if ( $count > 0 ) { foreach( $terms as $term ) {?> <section class=”achievement-section clearfix”> <?php $counter = 0; ?> <div class=” league-and-season clearfix”> <div class=”honour-league-name”> <?php echo $term->name; ?> </div> <?php $team = get_post_meta( … Read more

new WP_query > displays posts only once instead of running through full array

You can iterate over the array of IDs and look for the corresponding post in your results to generate output with duplicate posts: $post_ids = array( 208, 212, 218, 208, 212, 218 ); $args = array( ‘post_type’ => ‘custom_posttyp’, ‘order_by’ => ‘post__in’, ‘post__in’ => $post_ids, ); $the_posts = get_posts( $args ); foreach( $post_ids as $id … Read more

Sum and count of custom field values

Thanks for your help guys. They didn’t quit work exactly, but I managed to get the result I needed by doing the following $reviewsNum = 0; $reviewsCount = 0; $argsSchema = array( ‘post_type’ => ‘reviews’, ‘posts_per_page’ => -1 ); $loopSchema = new WP_Query( $argsSchema ); $count_reviews = wp_count_posts( ‘reviews’ )->publish; while ( $loopSchema->have_posts() ) : … Read more

Page listing all categories for CPT

I would create a page in the admin panel called service areas and create a rewrite rule that tells wp to load a corresponding page-service-areas.php template. function add_rewrite_rules () { add_rewrite_rule( ‘^service_areas/?$’, ‘index.php?pagename=service-areas’, ‘top’ ); } add_action(‘init’, ‘add_rewrite_rules’); Then in page-service-areas.php build out the query you want. The following link helps you visualize how wordpress … Read more

Add ‘page template’ column to dashboard for CPTs

<?php // add new column to the columns array function wpse267793_columns($columns) { // Column name $columns[‘template’] = ‘Template file’; return $columns; } function wpse267793_show_template_columns($name, $post_id) { // get template file name from post meta $template = get_post_meta($post_id, ‘_wp_page_template’, true); echo $template; } // change ‘CPT’ to the relevant custom post type add_filter(‘manage_CPT_posts_columns’, ‘wpse267793_columns’); add_action(‘manage_CPT_posts_custom_column’, ‘wpse267793_show_template_columns’, … Read more

Search for dates on custom post types

You need to use WP_Query for getting the posts which match your query. And in WP_Query you need to use the following: ‘meta_query’ => array( ‘meta_key’ => ‘date_started’, // change it to your custom field meta_key ‘type’ => ‘DATE’, // You can also try changing it to TIME or DATETIME if it doesn’t work ‘meta_value’ … Read more