How to query ‘posts_per_page’ to display a different blog posts index template?

You can control what template loads for any type of query via the Template Filters. Here’s an example using home_template that checks if posts_per_page is equal to 1, and loads single.php in that case. function wpd_home_template( $home_template=”” ){ if( get_option( ‘posts_per_page’ ) == 1 ){ $home_template = locate_template( ‘single.php’, false ); } return $home_template; } … Read more

Injecting content with $wp_query->current_post restarts from zero on paged pages. How to inject content after X posts, regardless of pagination?

For the record, I just found a new/different way to accomplish this goal. It’s not quite the same, but it does allow me to insert a new post type after every X posts in my original loop. This is the source: https://www.gowp.com/blog/inserting-custom-posts-loop/ The method was done via the code below, which essentially injects a new … Read more

query posts in wordpress

There is no term_id parameter. You need a tax_query. $args = array( ‘post_type’ => ‘my_post’, ‘posts_per_page’ => 6, ‘tax_query’ => array( array( ‘taxonomy’ => ‘yourtaxname’, ‘field’ => ‘id’, ‘terms’ => 1 ) ) ); $query = new WP_Query( $args ); Notice that I’ve use new WP_Query and not query_posts. Don’t use query_posts. Doing the above … Read more

Custom page template

Your code will only display a list of your posts if the page that is using that template is set to be the Posts Page (in admin settings). If you want any other page to display a list of posts, then you need to write a custom query inside the template. E.g. using WP_Query: $args … Read more

cloning a WP_Query

You shouldn’t have to “get your query back”. Your queries are all stored in different objects– $team, $reports_played, the original $wp_query, etc. Just access the particular object that you need to use. This is untested but to get functions like the_title working, run $query_object_name->the_post() at the top of each Loop iteration and $post = $parent_object_name->post … Read more

Get link of inserted media file of post within loop

You can get attachment URL like this. <?php if ( have_posts() ) : while (have_posts()) : the_post(); ?> <a href=”https://wordpress.stackexchange.com/questions/163795/<?php $featured_image_url = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ),”full’ ); echo $featured_image_url[0]; ?>”> <?php the_title(); ?> </a> <?php endwhile; endif; ?> First you will need to get the attachment ID so you will need to get it from … Read more

Getting two wp_link_pages output

Your theme is using old and deprecated function link_pages to display page-links for paginated posts. Just replace this chunk of code: <div class=”pagelink”><?php wp_link_pages(‘pagelink=Source %’); ?></div> <div class=”format_text”> <?php the_content(‘<p>Read the rest of this entry &raquo;</p>’); ?> <?php link_pages(‘<p><strong>Pages:</strong> ‘, ‘</p>’, ‘number’); ?> </div> with this: <div class=”format_text”> <?php the_content(‘<p>Read the rest of this entry … Read more

get_posts() seemingly ignoring post_type

I built a workaround for now, but would really love to know what is causing this. The workaround was obtained by removing changing “suppress_filters” to true and then adding a function that adds to the where clause of the SQL… But I would rather know how to fix this at the root rather than a … Read more