WordPress – query 5 posts with a specific post in top

You can do this by using get_adjacent_post() and the filter get_previous_post_where or get_next_post_where. You’ll call get_adjacent_post() as normal, but you’ll need to change the LIMIT to 5, using the filter. I wasn’t sure from the question whether or not you wanted to have the current post be first. If you do, you’ll need to set … Read more

Use get_post_types to query only custom posts types

Instead of creating a string try creating an array and check. $posttypes_array = array(); foreach ($post_types as $post_type ) { $posttypes_array[] = $post_type; } And then form the query as follows $buildArgsAllQuestions = array( // Add out new query parameters ‘post_type’ => $posttypes_array, //’post_type’ => $posttypes_array, ‘orderby’ => ‘date’, ‘order’ => ‘DESC’, );

Upcoming Event: How do I sort database by custom date field, but ignore past dates?

You’re pretty close, but I wouldn’t be distracted by the ‘scope’ meta key. The following is untested. <?php $args = array( ‘post__not_in’ => array($donotrepeat), “post_type” => ‘event’, ‘meta_key’ => ‘_event_start_date’, // name of custom field ‘orderby’ => ‘meta_value’, “order” => ‘ASC’, “posts_per_page” => 1, ‘meta_query’ => array( array( ‘key’ => ‘_event_start_date’, ‘value’ => date(‘Y-m-d’), ‘compare’ … Read more

Disable the MySQL query in the main query

Check if this solution work for your case: add_filter(‘posts_request’, ‘supress_main_query’, 10, 2); function supress_main_query( $request, $query ){ if( $query->is_main_query() && ! $query->is_admin ) return false; else return $request; } posts_request is the last filter called before running the query, and pass to you the $requestvariable with the generated SQL string and $query, with the WP_query … Read more

How to debug a blank page?

Notice: wpdb::escape is deprecated since version 3.6! Use wpdb::prepare() or esc_sql() instead. in /nfs/c01/h04/mnt/38315/domains/joao.pt/html/wp-includes/functions.php on line 2905 WordPress often is not really accurate with giving your information. You can change that: Set error_reporting( -1 ); and define( ‘WP_DEBUG’, true );. More info in that Gist. This will avoid the white screen of death. If you … Read more

Querying Term Posts in Loop

To expand on the answer from @s_ha_dum – you need to modify a few things about your query. First, use his suggested tax query: $args = array( ‘post_type’ => ‘custcpt’, ‘tax_query’ => array( array( ‘taxonomy’ => ‘custtax’, ‘field’ => ‘id’, ‘terms’ => $cat->term_id, ) ), ‘order’ => ‘ASC’ ); Then, modify your code as follows: … Read more

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