admin管理员组文章数量:1134557
My posts have a bunch of custom fields, to help insert and display custom info easily. I am trying to build a search that would select and display posts according values of specific 2 custom fields. The first field "type" is a radio button in my wp-admin, so in database its meta value is always one word. But second field is checkboxes, so in database meta value has several words, and I need to get posts that have the one visitor selects.
What I have so far:
- Search form, that consists of 2 dropdowns, each for one custom field. I use it one homepage: pastebin/zxPuGduW
- A function in functions.php, to select posts according the values set in dropdowns: pastebin/Z6D0GM4q
- A results page to show the posts according selections in the dropdowns form: pastebin/KHK0exWn
My posts have a bunch of custom fields, to help insert and display custom info easily. I am trying to build a search that would select and display posts according values of specific 2 custom fields. The first field "type" is a radio button in my wp-admin, so in database its meta value is always one word. But second field is checkboxes, so in database meta value has several words, and I need to get posts that have the one visitor selects.
What I have so far:
- Search form, that consists of 2 dropdowns, each for one custom field. I use it one homepage: pastebin.com/zxPuGduW
- A function in functions.php, to select posts according the values set in dropdowns: pastebin.com/Z6D0GM4q
- A results page to show the posts according selections in the dropdowns form: pastebin.com/KHK0exWn
1 Answer
Reset to default 0You should be able to do this with WP_Query
's meta_query
parameters:
$type = 'something';
$programme = 'another';
$args = array(
'meta_query' => array(
array(
'key' => 'type',
'value' => $type,
'compare' => '='
),
array(
'key' => 'programme',
'value' => $programme,
'compare' => 'LIKE'
)
)
);
$query = new WP_Query( $args );
本文标签: query specific posts according their custom fieldsusing sql SELECT
版权声明:本文标题:query specific posts according their custom fields, using sql SELECT 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736818565a1954189.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
WP_Query
instead of a raw SQL query? – Milo Commented Aug 24, 2013 at 16:54{}
button-- though it would be nice if it had line numbers. – s_ha_dum Commented Aug 24, 2013 at 17:20