Posts being viewed

I would suggest a way to implement this to be in the post template have a call that updates post meta with the current timestamp. Then you can show posts that have been viewed recently by querying meta data for all values within a certain time range ordered by that timestamp.

Different layout based on post amount?

for a standard query, you can check the amount of posts with: all posts for the query: $wp_query->found_posts and the posts on the page: $wp_query->post_count use that with a conditional statement to switch to the different layouts. example: <?php if ( have_posts() ) : //start of the loop// if ( $wp_query->found_posts <= 4 ) { … Read more

Restrict query_posts by Date?

I’ve done something in the past using custom fields. Maybe this can get you going in the right direction? This is done directly after the <?php while ( have_posts() ) : the_post(); ?> <?php $currentdate = date(“Ymd”); $expirationdate = genesis_get_custom_field(‘_racedate’); $expirestring = str_replace(“-“,””,$expirationdate); if (is_null($expirationdate)) { $expirestring = ‘30005050’; //MAKE UN-EXPIRING POSTS ALWAYS SHOW UP; … Read more

Pagination linking to first page

Perhaps you can take a look at this question and the answers and check if you really want to use query_posts() as it is not recommended while dealing with posts pagination. Why not use pre_get_posts action instead? Or you can try something like this: <?php $custom_query = new WP_Query(array( ‘post_status’ => ‘publish’, ‘post_type’ => ‘products’, … Read more

Displaying and Querying Posts with Featured image

Start by cleaning up your code; $args = array( ‘post_type’ => ‘post’, ‘posts_per_page’ => 3, ‘order’ => ‘asc’ ); $home_shows = new WP_Query($args); //setup your loop here if( $home_shows->have_posts() ): while( $home_shows->have_posts() ): $home_shows->the_post(); //fetch featured image if exists if ( has_post_thumbnail() ) { the_post_thumbnail(array(486,226)); } //fetch content the_content(); //etc… endwhile; endif; What output do … Read more

WordPress Query based on random taxonomy

<?php $all_books = get_terms( ‘history_books’ ); // Get all history book terms. $rand_book = $all_books[ array_rand( $all_books ) ]; // Select one at random. $related = get_posts( array( ‘posts_per_page’ => 5, ‘tax_query’ => array( array( ‘taxonomy’ => ‘history_books’, ‘terms’ => array( $rand_book->term_id ), ) ) ) ); ?> <h3> <a href=”https://wordpress.stackexchange.com/questions/104280/<?php echo get_term_link( $rand_book ) … Read more

Multiple instances of query_posts

If you have 8 categories, you need 8 queries. To improve your code use WP_Query instead of query_posts: <?php $categories = get_categories(); if ( ! empty($categories) ) { ?> <ul class=”tabs”> <?php foreach ($categories as $c ) { ?> <li> <a href=”#tab<?php echo $c->term_id; ?>”> <img src=”<?php bloginfo(‘template_directory’); ?>/images/logo-<?php echo $c->slug; ?>.png” alt=”<?php echo $c->name; … Read more

Can I use WP_Query one time and then filter the results multiple times

Wrap your WP_Query object in a function so you don’t have to change all the query $args. The function will pass parameters for custom field value and order by custom field value. Here how you can do it: <?php function custom_query($divided_cf_val=array(), $order_by_cf_val) { ?> <div id=”listings”> <?php $args = array( ‘post_type’ => ‘listing’, ‘post_status’ => … Read more

How can I list posts with different formats depending on order?

WP_Query will track which post is current. For example: $p = new WP_Query(array(‘post_type’=>’post’,’posts_per_page’=> 10)); if ($p->have_posts()) { while ($p->have_posts()) { $p->the_post(); echo $p->current_post.'<br>’; } } You could use that to selectively format your posts. For example $p = new WP_Query(array(‘post_type’=>’post’,’posts_per_page’=> -1)); if ($p->have_posts()) { while ($p->have_posts()) { $p->the_post(); switch ($p->current_post) { case 0: case 3: … Read more