How to filter custom posts by custom fields?

Hello! The problem is this: using the plugin Toolset Types created an arbitrary record type and added custom fields group (couple, single-line, numeric and checkbox), brought to the archives page, everything is shown, everything is fine, but now the next task, you need to add filters for these custom fields to be able to filter the content through Google, nothing intelligible can not find, can You tell me? Thank you!
July 2nd 19 at 16:56
1 answer
July 2nd 19 at 16:58
Solution
This is embedded by default in wp. You need to write the correct query using WP_Query. Be sure to specify in the query post_type(type records), and the parameters of random fields. Examples and description can be viewed here
You specifically need to look for an example of c the parameter 'post_type' => 'something out there', and sample 'meta_query' => array(something there)
In the end, you should receive an exemplary design view
$args = array(
 'post_type' => 'product',
 'meta_query' => array(
array(
 'key' => 'color',
 'value' => 'blue',
 'compare' => 'NOT LIKE'
)
)
);
$query = new WP_Query( $args );
Ivan, thank you very much for the answer! Tried to understand the material, so far I have only empty requests come( - tyshawn_Runte commented on July 2nd 19 at 17:01
: Start small, then add conditions that would understand what God is! - Kayden_McDermott80 commented on July 2nd 19 at 17:04
: after a couple of hours and read a book on the cycles of Wordpress (Brad Williams, David Damstra, Hal Stern) I understand how to work with WP_Query, the problem is just the same display was that the Types plugin Toolset was added to a meta_key prefix of "wpcf-" and when I added this prefix everything was wonderful to work with! Thank you very much for the reply, just figured out a very useful topic output cycles of wordpress. - tyshawn_Runte commented on July 2nd 19 at 17:07

Find more questions by tags WordPress