Get Multiple Data Outside The Loop In Variable

Hi,

Need some urgent help.

I stored my posts with mobile numbers in post_meta.

I am getting all the numbers with WP_Query

But all of the numbers are showing only in loop.

outside the loop if i called the variable i am getting the only one last mobile numbers of the post.

I need to send a bulk SMS to all those numbers outside the loop..

How can i do that?

Thanks

  • Shabir

    Here is my code.

    <?php $terms = get_the_terms( $post->ID , 'job-cats' );
    if($terms) {
    	foreach( $terms as $term ) {
    		$jobcats = $term->slug.',';
    	}
    };
    $args =  array(
    
    	'tax_query' => array(
    		'relation' => 'AND',
    		array(
    			'taxonomy' => 'job-cats',
    			'field'    => 'slug',
    			'terms'    => $jobcats,
    		),
    		array(
    			'taxonomy' => 'sub-cats',
    			'field'    => 'slug',
    			'terms'    => 'resume',
    		),
    	),
    	'posts_per_page' => -1,
    	  'orderby' => 'date',
    	  'order' => 'DESC',
        );
    $jobalert = new WP_Query($args);
    
    if ( $jobalert->have_posts() ) :
    while ( $jobalert->have_posts() ) : $jobalert->the_post(); ?>
    <?php $mobile = get_post_meta($post->ID, 'mobile', true);
    
    ?>
    
    <?php endwhile; ?>
    <?php else : endif; ?>
    <?php echo $mobile; ?>
  • Vaughan

    Hi shabir,

    Hope you're well?

    is $mobile an actual $var or is it an array?

    try var_dump($mobile); instead of echo.

    Or create an array instead of setting get_post_meta to true.

    <?php $mobile = get_post_meta($post->ID, 'mobile', false); ?>

    This should make $mobile return as an array then.

    Not sure if this is correct usage though, but give it a try & see, if not, we'll come up with something else.

    Hope this helps

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.