I am trying to:
I'm trying to make a custom type posts (its title and meta fields) output on a separate page. This page is created without using TOOLSET. I use standart Word Press query - "WP_query" for the page generation.
I add parameteres to the query:
'meta_query' => array(
array(
'key' => 'wpcf-reader-character’,
'value' => ‘Simpified No Pinyin’
)
)
The 'wpcf-reader-character’ field value is stored in the data base in the form of a line:
a:2:{s:64:"wpcf-fields-checkboxes-option-50aefeeb3fd87abda1ab0e2b08df76a6-1";a:1:{i:0;s:20:"Simplified No Pinyin";}s:64:"wpcf-fields-checkboxes-option-7b2fd2239a2df80de227ed74999f4b7d-1";a:1:{i:0;s:21:"Traditional No Pinyin";}}
Wpcf-reader-character field is created with the help of Toolset. It has 4 checkboxes in admin area. Usually it can be 2 chwckboxes set at one time.
I expected to see:
query results have values
Instead, I got:
The query results are empty.
How should I add the parameters to the query, so that I can find custom posts with 'wpcf-reader-character’ having the value 'Simpified No Pinyin’ ?
Thank you very much in advance.
Kindly send your answer to alex.p@mobecls.com
Dear pauline,
You can use meta_compare => 'LIKE' in the parameters, for example:
'meta_query' => array(
array(
'key' => 'wpcf-reader-character',
'value' => 'Simpified No Pinyin',
'meta_compare' => 'LIKE'
)
)
More help:
https://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters
meta_compare (string) - Operator to test the 'meta_value'. Possible values are '=', '!=', '>', '>=', '<', '<=', 'LIKE', 'NOT LIKE', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN', 'NOT EXISTS', 'REGEXP', 'NOT REGEXP' or 'RLIKE'. Default value is '='.
And we do not provide email support, we provide all support only on the forum.
Dear Luo,
Thank you very much for help.
That really helped!
Kind regards,
Alexander.