您当然可以使用Advanced Fields插件来实现这类功能,只需在创建自定义页面的查询中添加几行即可。我找到了documentation on checkboxes 从ACF获得帮助。滚动页面底部的代码示例,您将看到:
/*
* Query posts for a checkbox value.
* This method uses the meta_query LIKE to match the string "red" to
* the database value a:2:{i:0;s:3:"red";i:1;s:4:"blue";} (serialized array)
* The above value suggests that the user selected "red" and "blue" from
* the checkbox choices
*/
$posts = get_posts(array(
\'meta_query\' => array(
array(
\'key\' => \'field_name\', // name of custom field
\'value\' => \'"red"\', // matches exaclty "red",
//not just red. This prevents a match for "acquired"
\'compare\' => \'LIKE\'
)
)
));
if( $posts )
{
//...
}
您可以修改此代码以使用
WP_Query 也