Related posts with WP_Query

parent is your answer here. Every term have a parent value set in its parent property. This value is an integer value, and represent the term id of its parent term. All top level terms have a value of 0 which just simply means it is a top level term First we need to build … Read more

No exposure on search engines

Please go to Settings > Reading or wp-admin/options-reading.php If it’s not unchecked it will not allow search engines to reach. For further modification information related to robots you can use the below plugin to modify robots.txt file: Plugin – Multipart robots.txt editor To see your robots.txt file you would visit the link as: http://www.example.com/robots.txt

post__in not recognizing multiple IDs

This is more of a PHP than a WordPress issue: If $newstring = ‘15,30’; then array($newstring) is an array containing this string. If you print_r( array($newstring) ), it looks like this: Array ( [0] => 15,30 ) Which is not the same as array(15,30). What you want to do instead is: $newstring = ‘15,30’; $args … Read more

How much does $wpdb->prepare(), then $wpdb->query() VS straight $wpdb->query(), can slow down the load time of whole page

$wpdb->prepare shouldn’t make any significant difference. As you can see here (https://developer.wordpress.org/reference/classes/wpdb/prepare/#source), it doesn’t do much. It’s just taking care of proper escaping and formatting variables, so the final query is safe to run. So if you’re asking if there is a big difference between $wpdb->query( $wpdb->prepare( … ) ) and $wpdb->query( <SAFE_SQL> ), then … Read more

Pagination showing same posts despite changing page

After struggling for hours on this (and 6 years after the question was asked), for me the solution was lying within the $paged parameter: I changed $paged = ( get_query_var(‘paged’) ) ? get_query_var(‘paged’) : 1; to if ( get_query_var(‘paged’) ) { $paged = get_query_var(‘paged’); } else if ( get_query_var(‘page’) ) { $paged = get_query_var(‘page’); } … Read more

meta_query in wp_query not working as expected

It is not working because there is a custom query in the events plugin that adds the posts to be ignored (not returned) when you run WP_Query. See getHideFromUpcomingEvents() method in the-events-calendar/src/Tribe/Query.php. But there is however a filter hook that you can use there to do whatever. See the following sample code: function wpse283031_hide_ids( $ids … Read more

Wp query by 2 meta field – check if they exists / have value

Check the Codex. meta_query accepts an EXISTS comparison. $args = array( ‘post_type’ => ‘somepostype’, ‘meta_query’ => array( array( ‘key’ => ‘fname’.$userid, ‘compare’ => ‘EXISTS’, ), array( ‘key’ => ‘lname’.$userid, ‘compare’ => ‘EXISTS’, ) ) ); $query = new WP_Query( $args ); return $tempquery->found_posts; There is a note that… Note: Due to bug #23268, value is … Read more

wp_query->set for several categories

Try using tax_query: $tax_query = array( ‘relation’ => ‘AND’, array( ‘taxonomy’ => ‘category’, ‘field’ => ‘id’, ‘terms’ => 1 ), array( ‘taxonomy’ => ‘category’, ‘field’ => ‘id’, ‘terms’ => 2 ), array( ‘taxonomy’ => ‘category’, ‘field’ => ‘id’, ‘terms’ => 3 ) ); $query->set( ‘tax_query’, $tax_query );

WP_Query orderby not working on custom post_type

OK, I figured it pour reading about Orderby Parameters in WP_Query more carefully. I needed to set votes to meta_key and orderby to meta_value_num: $args = array( ‘post_type’ => ‘entry’, ‘meta_key’ => ‘votes’, ‘orderby’ => ‘meta_value_num’, ‘order’ => ‘DESC’, ‘posts_per_page’ => 10, ‘post_status’ => ‘publish’ ); $loop = new WP_Query($args);

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