Pagination for custom loop on custom page template is not displaying anything

Harman, don’t use get_posts() when pagination is required. You may also accomplish this task using WP_Query. Refer to this answer explained beautifully by Chip Bennett at How to fix pagination for custom loops? <?php $user_fav = get_user_favorites($user_id); $paged = ( get_query_var( ‘paged’ ) ) ? get_query_var( ‘paged’ ) : 1; $args = array( ‘posts_per_page’ => … Read more

How to check if there are posts with the same tag

this code is with in the loop of single.php , RIGHT? If so then give this code the try , it should work . Problem with your code seems that you are using showpost, rather you should be using posts_per_page Plus i see this fragments of code like `$test = “”; $test .= ‘,’ . … Read more

make get_post work in the loop

If you are using setup_postdata( $post ) you need to use the global $post as for some reason it does not work without that specific variable. Once you manually set $post to a new value, you are altering the $post global, so you will need to reset it back to the current post of the … Read more

Get_template_part() problem with the_content()

The problem is that you are running a loop from secondary query in front-page.php and the loop from main in page-home.php. So, the post data in page-home.php won’t be the data from the WP_Query in front-page.php. Additionally, you are trygin to get full template files as template parts, which is not correct. I mean, front-page.php … Read more

Limit tags shown in post

$count is just an arbitrary variable name. If you’re using a separate loop to get tags and stop after a certain number (as shown on https://codex.wordpress.org/Function_Reference/get_the_tags), replace the $count variable in that example code with something like $tag_count or $counting or $treebark, and it won’t mess up your use of $count in the posts Loop … Read more

Optimizing the blog loop

First of all: do not use query_posts use get_posts or new WP_Query instead. If you want to show only most viewed posts, you’ll need to add action ( for ex. wp ) check if your on single post page and update that post meta views ( +1 ). Then you could do something like these … Read more

Ordering posts by custom field and grouped by month

<?php $period = date(“Y-m-d”); $args = array( ‘post_type’=>’event’, ‘posts_per_page’=> -1, ‘order’=> ‘DESC’, ‘orderby’=> ‘meta_value’, ‘meta_key’=>’event_start_date’ ‘meta_value’ => $period, ) $events = new WP_Query( $args ); if ($events->have_posts()) : while (have_posts()) : the_post(); the_title(); // (etc.) endwhile; endif; ?> Please follow below link for details. Link for details link for code source Thanks!

Loop through incrementing custom fields

How can I loop through the fields and display the content without having to deplicate it? This for loop will cycle through the four field names to avoid duplication. <?php for ($i=1; $i<=4; $i++) { $fieldName=”featured_content_” . $i; $featuredContentPostID = get_field($fieldName)->ID; $selectedFeaturedContent = get_post( $featuredContentPostID ); ?> <li> <a href=”https://wordpress.stackexchange.com/questions/204839/<?php echo esc_url( get_permalink($featuredContentPostID) ); ?>”> … Read more

Not all posts showing in query

There seems to be a syntax in your Query: post_type=”posts&posts_per_page=-1″ would mean that your post type is posts&posts_per_page=-1 I think you mean $posts_query = new WP_Query(‘post_type=post&posts_per_page=-1’); (The post type is not posts, but post) In this case WordPress would not apply anyhting at all (because it contain errors, but just fetches the default post type … Read more