Search using specific meta fields only (excluding post title and content)

I have a custom post type my_cpt with 9 custom meta fields like first_name, last_name, location, phone, email etc along with post title and post content. Now what I want is to search using first_name and last_name fields only. See this sample post- Post Title: New Player (post title field of WP editor) Description: Lorem ipsum dolor sit (post content field of WP editor) first_name: John (custom meta) last_name: Doe (custom meta) phone: 123466789 (custom meta) email: [email protected] (custom meta) …
Category: Web

Working Bootstrap Carousel Conversion to WP - Technical Questions

I have coded a working Bootstrap carousel, it needs to be converted to WP. It's a small chunk of the site, but as a Wordpress newbie, am stuck in understanding the technical issue. So here's what I am trying to do: To show all those posts that have a featured image uploaded to show as a part of the Bootstrap carousel, then to limit the posts per page as needed. As a first step, I thought to not use WP_Query …
Category: Web

Meta query with JSON value

Im using post meta to store some value. Im having the following in wp_postmeta table: meta_key mykey meta_value a:2:{i:0;s:1:"5";i:1;s:1:"2";} I need to return posts which have meta_value of 2. My query: $args = array( 'post_type' => 'post', 'meta_key' => 'mykey', 'orderby' => 'meta_value_num', 'order' => 'ASC', 'meta_query' => array( array( 'key' => 'mykey', 'value' => '2', 'compare' => 'IN', ) ) ); $the_query = new WP_Query($args); But no posts returned... Where i made mistake?
Category: Web

Query multiple post types, but different order for each

I have a query which searches 2 post types as below: $args = array( 'post_type' => ['post', 'promotion'], 'posts_per_page' => 12, 'paged' => $paged, 's' => isset($_GET['search']) ? $_GET['search'] : '', ); This orders them by default, by published date. I need to add a third post type events. This however needs to be sorted by a custom field event_date asc and to disregard those which the event_date is in the past. Does anyone have any suggestions on how this …
Category: Web

How using the Meta Box plugin, to filter posts by the value of a post type field?

I'm using the Meta Box plugin to create custom post types and fields. There is a record type teachers, and I'm trying to display the lessons associated with him on the page of a certain teacher. The code looks like this: $queryArgs = array( 'post_type' => 'lessons', 'order' => 'ASC', 'posts_per_page' => -1, 'orderby' => 'meta_value', 'meta_key' => 'lessons_teacher', 'compare' => 'LIKE', 'meta_query' => [ [ 'key' => 'post_name', 'value' => 'john-smith', ] ] ); and here it is not …
Category: Web

meta_query 'compare' => '!=' not working

I am using a custom post-type, in post there are a checkbox meta field for featured post. So there are two scenarios. First with featured posts Second with non featured When I called featured posts with meta_query its result 100% perfect. Here is my code: $c_clients_args = array( 'post_type' => 'clients_testimonials', 'posts_per_page' => 6, 'order' => 'ASC', 'meta_query' => array( array( 'key' => 'c_client_feature', 'value' => 'on' ) ) ); $c_clients_result = new WP_Query($c_clients_args); if($c_clients_result->have_posts()) : while($c_clients_result->have_posts()) : $c_clients_result->the_post(); // …
Category: Web

How can I query for posts using a date stored in post-meta?

I’m working on a games release feature for a website I’m building. So far everything is going smooth, but I’m stuck on one area. For the listings on the front end, I want it to look at the “release_date” field and only display games that have a release date >= that date. I feel the code below should work, but it doesn’t return/display anything on the front end. And if I switch it to <=, it displays everything. Any help …
Category: Web

Create custom query for search?

I have create search box using ajax.If i enter any value in search input box that this value search in post title or post meta data and get all data of this value in custom post type.also query check only post title and specific post meta data. Not check in Post content or any other field. I have tried this query $args = array( 's' => $keyword, 'numberposts' => -1, 'post_type' => 'store', 'meta_query' => array( 'relation' => 'OR', array( …
Category: Web

How to cache the results of a query and display the cached results

I have a website centered around music. I have 3 main post types- 'Artist', 'Release', and 'Version'. There are 4 types of 'Version'- album, single, video, misc. Artist is parent of Release. (artist has a single -> many relationship with releases) Release is a parent of Version. (Release has a single-> many relationship with version) I've established these relationships in the plugin toolset types. In my single-artist page, I have releases displayed in sections. Here's an example of the code …
Category: Web

How to set up hierarchical relationships without using plugins / meta query

I'm running a large database of musical artists and their releases. I inherited the site after it running for a long time. There are currently several different custom post types, created with a Toolset plugin. The post types are hierarchical like this Artists | Directors | Releases | Albums | Singles | Videos | Misc | Artists and Directors are parent to Releases, which is a parent to the Version Albums | Singles | Videos | Misc | are the …
Category: Web

Meta query with order by another custom field

Edit: I will try to explain in detail my problem. I am working on a portfolio site. There are a few custom post types: Projects, Publications, Exhibitions, Lectures and Slides. Home page consists of following sections: slider with Slides portfolio consisting of: selected (marked by Client) Projects, Publications, Exhibitions and Lectures and remaining Projects, Publications, Exhibitions and Lectures awards section Now, I have problem with the portfolio section. It is to be paged in order to use Infinite Scroll by …
Category: Web

Order by the first array within a meta_query

I would like to sort the output of my WP Query. I want the events that are coming up soon to be at the beginning. The events that have already taken place should be at the end. So the first array in my meta_query should be output first, then the second array. $the_query = new WP_Query( array( 'post_type' => 'page', 'post_status' => 'publish', 'posts_per_page' => $posts, 'meta_key' => 'datum-von', 'orderby' => 'meta_value upcoming_events', 'order' => 'ASC', 'post__in' => array(22888,23062,23065,23348), 'meta_query' …
Category: Web

Attachment Metadata inside of Loop

Basically, I'm trying to call attachment info to display withing a loop, for use in an image gallery. I know I need to use wp_prepare_attachment_for_js($attachment_id) but I can't seem to get anything to show. Here's the HTML: <?php $the_query = new WP_Query(array( 'post_type' => 'attachment', 'post_status' => 'inherit' )); while ( $the_query->have_posts() ) : $the_query->the_post(); ?> <?php attachment_meta = wp_get_attachment($id); echo '<figure class="gallery-photo" itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject" data-groups='["all", "'.$attachment_meta['category_name'].'"]'><a class="photo-link" href="'.wp_get_attachment_image ().'">" itemprop="contentUrl" data-size="'.$attachment_meta[width].'"x"'.$attachment_meta[height].';?>"> <img src="'.wp_get_attachment_url ('fullsize').'" itemprop="thumbnail" /> <figcaption itemprop="caption …
Category: Web

How to add date_query to meta_query array

I am building a meta query array and all fields for the user are optional so some might not have any data. But there is also an option which requires a date query. I am still checking to see if this is working but not sure as of yet. Is this correct and if not, what would be the right way to do it? Not sure if there needs to be an OR condition in here somewhere. $meta_query = []; …
Category: Web

meta_query with meta values as serialize arrays

I'm working on a project in which I'm creating a custom post type and custom data entered via meta boxes associated with my custom post type. For whatever reason I decided to code the meta boxes in such a way that the inputs in each metabox are part of an array. For instance, I'm storing longitude and latitude: <p> <label for="latitude">Latitude:</label><br /> <input type="text" id="latitude" name="coordinates[latitude]" class="full-width" value="" /> </p> <p> <label for="longitude">Longitude:</label><br /> <input type="text" id="longitude" name="coordinates[longitude]" class="full-width" value="" …
Category: Web

Get posts with multiple meta values

I have a ACF select field which takes multiple value. Now I want to use get_posts() to get those custom posts. My arguments look like this: $party = 'test1'; $function = 'test1, test2'; $args = array( 'numberposts' => -1, 'post_type' => 'event', 'meta_query' => array( 'relation' => 'AND', array( 'key' => 'party', 'compare' => '=', 'value' => $party, ), array( 'key' => 'function', 'compare' => 'IN', 'value' => array($function), ) ) ); $items = get_posts($args); But this does not work! …
Category: Web

How to use germ_terms() with meta_query for ACF Taxonomy field?

I have a custom taxonomy, Events (“event”). Through ACF, this also has a Taxonomy field, “Topic”, linking it to a secondary taxonomy, Topic (“topic”). I want to get_terms() for all Events terms which bear the specific “Topic” term “Media”, which happens to have term ID 422. I know get_terms() can take meta_query, but I don’t understand how to properly get what I need. Both of these return no results… 'meta_query' => array( array( 'key' => 'Topic', 'value' => '422', ) …
Category: Web

Order WP_Query by meta_key priority when 'OR' relation used for multiple meta values

I have a WP_Query that queries posts by an ACF date field AND an ACF true/false field. I am requesting all posts that have a date field value past the current date OR have the true/false field checked true be returned. It appears like such: $args = array( 'post_type' => 'post', 'posts_per_page' => 6, 'meta_key' => 'event_date', 'orderby' => 'meta_value_num', 'order' => 'ASC', 'cat' => 3, 'meta_query' => array( 'relation' => 'OR', array( 'key' => 'event_date', 'value' => date('Ymd'), 'compare' …
Category: Web

WP get_posts meta_query using ACF repeater field

I have a Custom Post Type of 'ITEM' that allows the admin to add an 'Item Number' using an ACF text field. In another Custom Post Type of 'GROUP' the admin can use an ACF Repeater to enter multiple 'Item Numbers' for 'ITEMS' to associate with this GROUP. I need the loop to show all posts that have an 'Item Number' that matches a number entered into the Repeater on the Group Page. I'm using get_posts() to query on a …
Category: Web

Display post in order of ACF checkbox?

I have a custom post type called ‘Skateboards’. Within the custom post type of ‘Skateboards’ , I added three checkboxes (filed type checkbox) with a field name of ‘skateboard_performance’ associated to the ’Skateboards’ custom post type via ACF. The values of the three check boxes are ‘Platinum’ , ‘Gold’ and ‘Silver ’. What I am trying to accomplish is to display the ‘Skateboards’ post type in order of ‘Platinum’ , ‘Gold’ and ‘Silver’. So all of the Skateboards posts marked …
Category: Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.