have_posts() return false on single post

Late answer but, one possible scenario this could be happening is if you register two custom post types with the same permalink slug. You can debug this by doing a var_dump of the global variable $wp_query. global $wp_query; var_dump($wp_query); Check to see if the post_type in the query matches the post type of the page … Read more

‘posts_per_page’ => ’10’ does not show any post

after days of research, I found that the fault was simply in the pagination. By changing the pagination code, I have made it work. <?php $paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1; $custom_args = array( ‘post_type’ => ‘veranstaltungen’, ‘orderby’ => ‘date’, ‘order’ => ‘DESC’, ‘paged’ => $paged, ‘posts_per_page’ => ’10’ ); $wp_query = new WP_Query($custom_args); … Read more

Get custom taxonomy value of post and output posts in same taxonomy

try with this function function get_posts_in_taxonomy($post_type, $taxonomy, $term_id, $include_children=false, $limit) { $args = [ ‘post_type’ => $post_type, ‘posts_per_page’ => $limit, ‘tax_query’ => [ [ ‘taxonomy’ => $taxonomy, ‘terms’ => $term_id, ‘include_children’ => $include_children ], ], // Rest of your arguments ]; $posts = new WP_Query( $args ); if($posts->have_posts()) { while($posts->have_posts()) { $posts->the_post(); //code todo here … Read more

How to implement template file and the loop

I have seen that there is extra (); so maybe this syntax error prevent display in front-end please try below code – <?php /** * Template Name: Basic Test */ get_header(); if ( have_posts() ) : while ( have_posts() ) : the_post(); the_title(); endwhile; else : _e( ‘Sorry, no posts matched your criteria.’, ‘textdomain’ ); … Read more

Exclude post formats in custom loop

$args=array( ‘paged’=>$paged, //Pulls the paged function into the query ‘posts_per_page’=> 4, //Limits the amount of posts on each page ‘post_type’=>’post_type’, //Set your allowed post types here ‘orderby’ => ‘title’, ‘order’ => ‘ASC’ ); query_posts($args); For more reference refer this. You can pass the allowed post_type array to post_type argument in arguments array.

Display custom field outside the loop

<?php define(‘WP_USE_THEMES’, false); require(‘wp-blog-header.php’); ?> <?php $post_id = 288; echo get_post_meta($post_id, ‘caption’, true); ?> That part is enough – are you sure that this is the name of your custom field and the path to wp-blog-header is resolved and valid?