1

I have a custom loop for showing child pages of the current page, but I'd like to allow the WP user to enter page IDs to be excluded from the loop, using Advanced Custom Fields. My current loop is as follows. It almost works, except it only excludes the first page ID in the list:

<?php     
 $exclude_ids = get_field('exclude_pages');
 $args = array (
 'post_type' => 'page', // custom post type
 'post_parent' => $post->ID,
 'orderby' => 'menu_order title', 
 'order' => 'ASC',
 'posts_per_page' => -1,
 'post__not_in' => array( $exclude_ids )
);?>

And the Advanced Custom Field is set as a text field, with no formatting. In that parent page, I have entered the page IDs in the ACF field as 2147,2145 (no quotes, no parenthesis). Interestingly, when I echo the variable, it shows the page IDs correctly, but it's just not working when it's part of the array...?

What am I doing wrong? Thank you!!! C

1
  • Don't forget to mark the answer as accepted please so future users can find help as well. This will also continue to show in the unanswered questions queue.
    – jdm2112
    Commented Nov 15, 2016 at 17:24

1 Answer 1

1

Convert your string of IDs into a proper array:

$exclude_ids = get_field( 'exclude_pages' );
$exclude_array = explode( ",", $exclude_ids );

Then pass $exclude_array as the value for post__not_in.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.