Opened 15 months ago
Closed 15 months ago
#20079 closed defect (bug) (invalid)
wp_query excludes posts without custom field from search
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Query | Version: | 3.3.1 |
| Severity: | normal | Keywords: | |
| Cc: |
Description (last modified by SergeyBiryukov)
Merging these arguments with the query in search, excludes posts that do not have the custom field 'statut' from search.
$args = array(
'posts_per_page' => $per_page,
'orderby' => 'title',
'order' => 'ASC',
'post_type' => 'medicament',
'post_status' => 'publish',
'meta_query' => array(
// exclude non commericalisés médicaments
array(
'key' => $prefix.'statut',
'value' => 'Non commercialisé',
'compare' => '!=',
'type' => 'CHAR',
),
)
);
Change History (2)
Note: See
TracTickets for help on using
tickets.

Yes, that's expected behavior. To also get posts that don't have the custom field at all, you'll have to write:
'meta_query' => array( 'relation' => 'OR', array( 'key' => $prefix.'statut', 'value' => 'Non commercialisé', 'compare' => '!=', 'type' => 'CHAR', ), array( 'key' => $prefix.'statut', 'compare' => 'NOT EXISTS', ), )Note that 'NOT EXISTS' is not implemented yet: #18158