如何通过Advanced Custom Fields复选框筛选自定义特色房产文章?
Hey there! Let's get that featured property filter working properly. The issue here boils down to how ACF stores checkbox values—even if you only select one option, it gets saved as a serialized array in the database, not a plain string. That's why your original query (looking for a direct "Yes" match) isn't finding anything.
Here's the corrected query to use:
$args = array( 'post_type' => 'property', 'posts_per_page' => 1, 'meta_query' => array( array( 'key' => 'featured_property', 'value' => 'Yes', 'compare' => 'LIKE' ) ) ); $query = new WP_Query( $args );
Why this works:
ACF saves checkbox selections as serialized data (e.g., a:1:{i:0;s:3:"Yes";} for a single "Yes" selection). Using the LIKE comparison operator lets WordPress match the "Yes" string inside that serialized array, which your original meta_value check couldn't do.
A more precise alternative:
If you want to avoid potential false matches (unlikely here if "Yes" is unique), you can target the array directly with the IN comparison:
$args = array( 'post_type' => 'property', 'posts_per_page' => 1, 'meta_query' => array( array( 'key' => 'featured_property', 'value' => array('Yes'), 'compare' => 'IN' ) ) ); $query = new WP_Query( $args );
Quick sanity checks:
- Double-check your ACF field settings: Ensure the "Return Value" is set to "Value" (not "Label") if you're using "Yes" as the option value.
- Verify the field key exactly matches
featured_property—typos are a super common culprit!
内容的提问来源于stack exchange,提问作者Reece

