Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save JamesHusband/8bde7c75b83570a0850fc76b36db0d2e to your computer and use it in GitHub Desktop.
Save JamesHusband/8bde7c75b83570a0850fc76b36db0d2e to your computer and use it in GitHub Desktop.
function lsmwp_post_exclusion() {
$posts = lsmwp_excluded_posts();
$result = array();
var_dump( $posts );
foreach ( $posts as $post ) {
$res = lsmwp_post_limiter( $post['postId'], $post['in'], $post['count'] );
if ( $res ) {
$result[] = $res;
}
}
$data = $result;
var_dump( $result );
return $result;
}
// Selected posts for limiting
function lsmwp_excluded_posts() {
$excluded_posts = array();
if ( get_field( 'posts_to_limit', 'option' ) ) :
while ( the_repeater_field( 'posts_to_limit', 'option' ) ) :
$posts = get_sub_field( 'operator' );
if ( $posts ) :
foreach ( $posts as $p ) :
$id = $p;
endforeach;
endif;
$excluded_posts[] = array(
'postId' => $p,
'in' => get_sub_field( 'in' ),
'count' => get_sub_field( 'count' ),
);
// the_sub_field( 'in' );
endwhile;
endif;
return $excluded_posts;
}
// Post Limiter
function lsmwp_post_limiter( $ids, $in, $count ) {
$count = (int) $count;
$i = rand( 1,$count );
if ( $i <= $in ) {
return($ids);
} else {
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment