Articles of meta query

WordPress & MySQL , problem with use many array in meta_query

I use this code for display custom posts : $args = array( ‘category__in’ => $bookcat, ‘meta_query’ => array( ‘relation’ => ‘OR’, array(‘key’ => ‘bookname’,’compare’ => ‘LIKE’,’value’ => $bookname), array(‘key’ => ‘authr’,’compare’ => ‘LIKE’,’value’ => $authr), array(‘key’ => ‘translator’,’compare’ => ‘LIKE’,’value’ => $translator), array(‘key’ => ‘publisher’,’compare’ => ‘LIKE’,’value’ => $publisher), array(‘key’ => ‘pyear’,’compare’ => ‘=’,’value’ => […]

WP_Query not returning correct result with meta_query parameter

I’ve got the following loop on my index.php template: <div id=”new_on”> <?php $args = array( ‘meta_query’ => array( ‘meta_key’ => ‘is_url’, ‘meta_value’ => ‘yes’, ‘meta_compare’ => ‘NOT LIKE’ ), ); $main_query = new WP_Query( $args ); while ( $main_query->have_posts() ) : $main_query->the_post(); ?> <h2><a href=”<?php the_permalink(); ?>”><?php the_title(); ?></a></h2> <div class=”clearfix smalltext”><span class=”left”><a href=”<?php the_author_link(); […]

How can I modify my meta_query to work with prices that are stored in the database that contain dollar signs and commas?

My goal is to return posts based on a specific price range using meta_query. The price in the admin that the user enters is a custom field, created using WPAlchemy. In the example below, the query would return any posts with a price value between 1000 and 1500: ‘meta_query’ => array( array( ‘key’ => ‘_my_price’, […]

Custom query looking at multiple custom fields and properly sorting

For the past two weeks I’ve been looking for a way to create a query in wordpress that returns all custom post types where a meta_key “mytype-expired” is NOT set to “yes” and then order the results by a second meta_key called “mytype-sort-order” with the highest number value coming first. If no value exists in […]

How can I change my meta_query to SQL wpdb query?

I want to extract post related to 3 meta_data fields called bed_value, bath_value, rob_value the variable data is $bedrooms, $bathrooms, &rob, I got some confused with join and like structure. The unworking metaquery is this $args = array( ‘meta_query’ => array( ‘relation’ => ‘OR’, array( ‘key’ => ‘beds_value’, ‘value’ => $bedrooms, ‘compare’ => ‘=’, ), […]

meta_query displays all results and none, my query is wrong

I´ve read almost this articles but unfortunately my query is no working, I think i´m very close but could be so far away. I´m trying to get metadata using a custom form with method get, $rob = $_GET[‘rob’]; $bedrooms = $_GET[‘beds’]; $bathrooms = $_GET[‘baths’]; the array is $args = array( ‘meta_query’ => array( array( ‘key’ […]

Is it possible to compare the current time with a custom “start” and “end date

I need to be able to display a custom post type if the current date is between the start and end custom meta field dates. Here is my code so far, it seems to just be ignoring the query and displaying all 3 of the posts, I have probably made a mistake as I have […]

Help With issue on pre_get_posts filter in taxonomy

I create a function to filter the taxonomy query with this code add_action(‘pre_get_posts’, ‘custom_taxonomy_query’); $option_taxposts_per_page = get_option(‘tax_posts_per_page’); function custom_taxonomy_query(&$query) { global $option_taxposts_per_page; if (!is_admin() && is_tax(‘feature’) || is_tax(‘propertytype’) || is_tax(‘location’)) { if (is_tax(‘feature’)) { $browseorder = get_option(‘browse_feature_order’); } else if (is_tax(‘propertytype’)) { $browseorder = get_option(‘browse_propertytype_order’); } else if (is_tax(‘location’)) { $browseorder = get_option(‘browse_location_order’); } switch […]

Best way to sort estates and query them (for rent? yes/no. contains office space? yes/no)?

I´m building a real estate site where Estates is a custom post type. I want to be able to tick a checkbox or something similare on the edit page, where I can choose if the estate is for rent, if it contains office space etc. And then be able to query against this in different […]

filter custom post type by meta key in dashboard

I’m looking for a way to expand e customize more this topic How to filter post listing (in WP dashboard posts listing) using a custom field (search functionality)? I’ve a custom post type in the dashboard i’ve managed to have a small search box with a fixed search function to search a specific meta key. […]