wp_query random post

Doing this in PHP is an awful idea: This page is impossible to cache ordering by random is extremely expensive to query, involving creating temporary database tables, and scans, as it has to copy the entire posts table, then randomly re-order the posts, then finally do the actual query on the new table before destroying … Read more

meta_compare not comparing whole integer

You could try this instead: $bc_args = array( ‘post_type’ => ‘data’, ‘data-category’ =>’insurance-rate’, ‘order’ => ‘DESC’, ‘orderby’ => ‘meta_value_num’, ‘meta_query’ => array( array( ‘key’ => ‘interest_rate’, ‘value’ => (int) $i_rate, ‘type’ => ‘numeric’, ‘compare’ => ‘>=’ ), ) ); $sortedPosts = new WP_Query( $bc_args ); where we use the numeric type. You should also consider … Read more

Pagination for blog posts reloading same page [closed]

$my_query = new WP_Query( array( ‘posts_per_page’ => 3, ‘paged’ => get_query_var(‘paged’) ) ); while ( $my_query->have_posts() ) : $my_query->the_post(); the_title(); // more stuff here endwhile; wp_pagenavi( array( ‘query’ => $my_query ) ); wp_reset_postdata(); try this code and also increase the size of show posts in SETTINGS->Reading->Blog pages show at most 10 to 50 or 100, … Read more

How to change main query to only query posts from a single category? [duplicate]

<?php $catquery = new WP_Query( array( ‘post_type’ => ‘post’, ‘category_name’=>’hello’,’posts_per_page’ => 5 ) ); while($catquery->have_posts()) : $catquery->the_post(); ?> <ul> <li> <h3> <a href=”https://wordpress.stackexchange.com/questions/295915/<?php the_permalink() ?>” rel=”bookmark”><?php the_title(); ?></a> </h3> </li> <li> <?php the_content(); ?> </li>

pagination not working for category.php (custom post types in categories)

<?php $catname = wp_title(”, false); $wp_query = new WP_Query(); $wp_query->query(‘category_name=”.$catname.”&showposts=5′.’&paged=’.$paged); ?> <?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?> <?php the_title(); ?> <?php } ?> <?php endwhile; ?> <?php next_posts_link(‘&laquo; Older Entries’) ?> <?php previous_posts_link(‘Newer Entries &raquo;’) ?> I think that you need to look at the $paged variables.