[wp-trac] [WordPress Trac] #43747: $query set post__not_in not accepting inputs from variables correctly (was: $query set post__not_in not accepting inputs from varaibles correctly)

WordPress Trac noreply at wordpress.org
Thu Apr 12 14:52:54 UTC 2018


#43747: $query set post__not_in not accepting inputs from variables correctly
--------------------------+----------------------
 Reporter:  Venutius      |       Owner:  (none)
     Type:  defect (bug)  |      Status:  closed
 Priority:  normal        |   Milestone:
Component:  Query         |     Version:
 Severity:  normal        |  Resolution:  invalid
 Keywords:                |     Focuses:
--------------------------+----------------------
Changes (by swissspidy):

 * status:  new => closed
 * resolution:   => invalid
 * component:  General => Query
 * milestone:  Awaiting Review =>


Comment:

 Hi there

 The documentation for `post__not_in` is pretty clear:

 > An array of post IDs not to retrieve. Note: a string of comma-separated
 IDs will NOT work.

 `array(316,319,321)` is an array of integers, which are post IDs.

 In your example, `array($exclude_string)` is the same as writing `array(
 '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 ) ) );`.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/43747#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list