Opened 8 years ago
Closed 8 years ago
#43747 closed defect (bug) (invalid)
$query set post__not_in not accepting inputs from variables correctly
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Priority: | normal | |
| Severity: | normal | Version: | |
| Component: | Query | Keywords: | |
| Focuses: | Cc: |
Description
If I enter:
$query->set('post__not_in', array(316,319,321));
posts 316, 319 and 321 are excluded from the loop.
However, if I do:
$exclude_string = '316,319,321';
$query->set('post__not_in', array($exclude_string));
Only post 316 is excluded. Can't see where I'd be doing something wrong here.
Change History (1)
#1
@
8 years ago
- Component changed from General to Query
- Milestone Awaiting Review deleted
- Resolution set to invalid
- Status changed from new to closed
- Summary changed from $query set post__not_in not accepting inputs from varaibles correctly to $query set post__not_in not accepting inputs from variables correctly
Note: See
TracTickets for help on using
tickets.
Hi there
The documentation for
post__not_inis pretty clear:array(316,319,321)is an array of integers, which are post IDs.In your example,
array($exclude_string)is the same as writingarray( '316,319,321' ). This is an array with one item, a string containing a comma-separated list of post IDs.To make your code work, just use
$query->set( 'post__not_in', array( implode( ',', $exclude_string ) ) );.