how to add limit records in wordpress query

What you want to do, can be achieved by means of the WP_Query class. $query = new WP_Query(array( ‘post_type’ => ‘quote2’, ‘posts_per_page’ => 10, // or something else )); Now you can work with $query like: if ($query->have_posts()) { while ($query->have_posts()) { $query->the_post; ?> <h1><?php the_title(); </h1> <?php the_content(); <?php } else { // No … Read more

Get posts after calculating meta key

Assuming meta_count is another column in your postmeta table below query should get you the posts based on meta_value/meta_count calculation. $postids=$wpdb->get_col( $wpdb->prepare( “SELECT post_id FROM $wpdb->postmeta ORDER BY (meta_value/meta_count) LIMIT 10 ” ) ); The result $postids would be an array. You will have to declare $wpdb as a global variable before you use this … Read more

Edit WordPress loop, taxonomies, & filter

Your code makes it hard for anyone to help you. It is important to properly edit your code in your question. You really don’t have to use the amount of echo‘s you are using. It is just poor formatting and poor use of proper tags. You can clean up your code by just properly opening … Read more

WP_Query with tax_query not working

SQL query forming is wrong SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts WHERE 1=1 AND 0 = 1 AND wp_posts.post_type=”product” AND (wp_posts.post_status=”publish”) GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0, 1 Here 1=1 AND 0 = 1

How to retrieve posts from parent category, splitting them per children when displayed?

Calling WP_Query three times isn’t too good for performance, as it will make three queries to the database. The way you’re currently approaching this seems like the proper (and fastest) way in may opinion. However, you should be calling $category_posts->rewind_posts() after each while-loop to reset WP_Query‘s loop to the first post. Furthermore, your current way … Read more

Query custom post types by meta field in a term from custom taxonomy

Assuming that the query works and you get all posts with ss_category terms (instead of those with ss_aff_category = true only), I think this should work: $args = array( ‘post_type’ => array(‘advertisers_cats’), ‘posts_per_page’ => 9, ‘tax_query’ => array( array( ‘taxonomy’ => ‘ss_category’, ‘terms’ => array(100, 101), ‘field’ => ‘term_id’, ) ), ‘meta_query’ => array( array( … Read more