Multiple loop for “featured” items returns wrong posts

Your second loop is fine because it works – although it is probably more efficient to do it this way: $args = array( ‘post_type’ => ‘onourradar’, ‘posts_per_page’ => -1, ‘orderby’ => ‘menu_order’, ‘order’ => ‘ASC’, ‘offset’ => ‘2’); $my_query = new WP_Query($args); while ($my_query->have_posts()) : $my_query->the_post(); The difference is that a do_not_duplicate query is just … Read more

How to limit post query to only return a total count of items with certain post statuses?

WHERE post_status NOT IN (‘auto-draft’,’trash’) Looks like you can add that to your base query. /* — Preparing your query — */ $query = “SELECT * FROM $wpdb->posts WHERE post_status NOT IN (‘auto-draft’,’trash’) “; This is only barely a WordPress question. Why are you not using core functions for this? Also, NOT IN is not … Read more

Custom MySQL query to list post

You don’t need to use query_posts function. It could be done without it. Use setup_postdata function to set up global post data. $sql = ” SELECT p.* FROM orders_items oi INNER JOIN products pr ON pr.`post_id` = oi.`product_id` INNER JOIN posts p ON p.`ID` = pr.`post_id` AND p.`post_type` = ‘product’ GROUP BY oi.`product_id` ORDER BY … Read more

Dropdown Menu for Query_Posts

Here’s a simple example of a PHP dropdown, hope this helps. <select name=”mydropdownlist”> <?php $options = array(‘option1’ => ‘option 1’ ‘option2’ => ‘option 2’ ‘option3’ => ‘option 3’); foreach($options as $value => $caption) { echo “<option value=\”$value\”>$caption</option>”; } ?> </select>

How to apply order on custom taxonomy and custom meta key on custom post type

I think the simplest way would be to run the loop for each status and only output posts that match the current status: $statuses = array( ‘Active’, ‘Pending’, ‘Sold’ ); foreach( $statuses as $status ): echo $status; while( have_posts() ): the_post(); if( has_term( $status, ‘vr_listing_status’ ) ): the_title(); endif; endwhile; rewind_posts(); endforeach; A couple of … Read more

WordPress plugin not eching popular posts

one possibility is: public function popularPosts($num) { global $post; $args = array( ‘orderby’ => ‘comment_count’, ‘order’ => ‘DESC’ ); $posts = get_posts( $args ); $count = 0; foreach ($posts as $post): if($post->comment_count != 0 ){ $count++; } endforeach; if ( $count > 0 ): foreach( $posts as $post ) : setup_postdata($post); if($post->comment_count != 0 ){ … Read more

How to optimize ‘select found_rows()’ query? Several ‘high load average’ alerts daily

This should not break pagination: add_filter(‘pre_get_posts’, ‘optimized_get_posts’, 100); function optimized_get_posts() { global $wp_query, $wpdb; $wp_query->query_vars[‘no_found_rows’] = 1; $wp_query->found_posts = $wpdb->get_var( “SELECT COUNT(*) FROM wp_posts WHERE 1=1 AND wp_posts.post_type=”post” AND (wp_posts.post_status=”publish” OR wp_posts.post_status=”private”)” ); $wp_query->found_posts = apply_filters_ref_array( ‘found_posts’, array( $wp_query->found_posts, &$wp_query ) ); if($wp_query->query_vars[‘posts_per_page’] <= 0) { $wp_query->max_num_pages = 0; } else { $wp_query->max_num_pages = ceil($wp_query->found_posts … Read more

single.php fires more than once after clicking on any post to view with different post id each time

I am answering this because nobody yet answered this and I think this could help others who are experiencing this kind of issue. As mentioned by s_ha_dum that the issue is related to FireFox’s Prefetching mechanism. In order to resolve this I inserted the below line to function.php: remove_action(‘wp_head’, ‘adjacent_posts_rel_link_wp_head’);

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)