Different page parameters inside query
NO, you cannot combine post_in and post_not_in in the same query. Both are mutually exclusive, So it is impossible for mutually exclusive events to occur at the same time.
NO, you cannot combine post_in and post_not_in in the same query. Both are mutually exclusive, So it is impossible for mutually exclusive events to occur at the same time.
Expanding a bit on the answer from @dgarceran Generally, using the WP_Query class is probably a good idea for querying posts. We’ll want to pass arguments to that query. In your case we’ll likely want use one of the following: “Custom Field Parameters” – meta_query “Taxonomy Parameters” – tax_query For a nearly comprehensive example of … Read more
You can use pre_get_posts with a callback: <?php defined( ‘ABSPATH’ ) OR exit; /** Plugin Name: (#102854) Order Posts by Foo */ add_filter( ‘pre_get_posts’, ‘wpse_102854_orderby_foo’ ); function wpse_102854_orderby_foo( $query ) { if ( ! $query->is_main_query() OR ! is_admin() OR ‘edit.php?post_type=YOUR_POST_TYPE’ !== $GLOBALS[‘parent_file’] // Other conditions that force an abort, Example: // OR ‘foo’ !== $query->get( … Read more
The correct syntax for performing the AND OR is as follows: ‘meta_query’ => array( ‘relation’ => ‘AND’, array( ‘key’ => ‘flagged’, ‘value’ => ‘1’, ‘compare’ => ‘!=’ ), array( ‘relation’ => ‘OR’, array( ‘key’ => ‘expiry_date’, ‘value’ => date(‘Y-m-d’,strtotime(“today”)), ‘compare’ => ‘>=’, ‘type’ => ‘DATETIME’, ), array( //has no date ‘key’ => ‘expiry_date’, ‘value’ => … Read more
meta_query parameter is an array of arrays, $args = array( ‘meta_query’=> array( array( ‘relation’ => ‘AND’, array( ‘key’ => ‘minbeds’, ‘value’ => $rooms, ‘compare’ => “<=”, ‘type’ => ‘numeric’ ), array( ‘key’ => ‘maxbeds’, ‘value’ => $rooms, ‘compare’ => “>=”, ‘type’ => ‘numeric’ ), array( ‘key’ => ‘minprice’, ‘value’ => $price, ‘compare’ => “<=”, ‘type’ … Read more
The solution was that I need to compare the literal value of $projectID, so that LIKE compares an exact string instead of just numbers. To make $projectID literal, it needs to be wrapped in quotes. So, I changed this line: ‘value’ => $projectID, to: ‘value’ => ‘”‘.$projectID.'”‘, Which solves the problem.
I did something similar for a client a while back, I’ll give you some of the code here as-is that you can possibly adapt to your needs. I’ll warn you, it’s quite a bit to parse through! First, I set up some custom rewrite rules to get the year/month URL structure and some query vars … Read more
Update – it may be supported in a meta_query. I need more information – see below. You can’t do it using a meta_query, it’s not supported. Do you have data in meta_data fields? – WordPress queries will exclude posts where any of the orderby (or meta_query) fields is missing. WordPress adds a join condition to … Read more
Yes, it behaves weird. No, shoot me, I can’t get a fix on precisely why and how (stacked joins are probably it). I say flip it. The only posts you don’t want to see are those with true custom key. Query for their IDs separately, feed result into post__not_in, ditch this meta query entirely.
There is no need to craft a custom SQL query in order to achieve this. Since version 4.1, WordPress’s query classes have supported complex/nested meta queries. So you can craft a query like this: $args[‘meta_query’] = array( // Use an OR relationship between the query in this array and the one in // the next … Read more