To illustrate I’ve this Question to which I fetch all my WP posts after which use PHP to filter out even additional:
<?php
$posts = get_posts(array(
'tax_query' => array(
array(
'taxonomy' => 'sort',
'area' => 'slug',
'phrases' => array( 'marketing campaign' ),
),
),
'post_type' => 'publish',
'posts_per_page' => 999999999999999999,
'orderby' => 'rand',
));
if( $posts): ?>
<?php foreach( $posts as $publish ): setup_postdata( $publish ) ?>
// Filter out customers with funds with PHP
<?php
$post_id = get_the_ID();
$advertiser_id = get_post_field( 'post_author', $post_id );
$advertiser_userfunds=get_user_meta( $advertiser_id, 'userfunds' , true );
if ($advertiser_userfunds > 0):?>
//5 posts left within the loop after filtering out customers with funds
<?php endif;?>
<?php endforeach; ?>
<?php wp_reset_postdata(); ?>
<?php endif; ?>
So as an example I am left with a loop of 5 posts now.
My query is, is there any strategy to present simply 1 publish?
It may be in a random order, or just displaying first or final publish from the loop?
I do know there is a php code if in_array()
. Perhaps I might implement this in some way?
Desperately need assistance.