Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Wp Members conditional loop WordPress

  • SOLVED

How do i echo a loop if i have a wp members field

if ($current_user->phone == 'iphone5'){
echo '<img src="'.get_bloginfo('template_directory').'/profile/img/ip5.png" alt="ip5" />';



loop example to show if phone == iphone5


<?php
$cat_id='-8';//the category ID
$limit = get_option('posts_per_page');

query_posts(array(
'showposts'=>32,'more' => $more = 0,
'orderby' => 'meta_value_num',
'meta_key' => 'sales_count',
'order' => 'DESC',
'paged' => $paged
));?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<li <?php post_class() ?> id="post-<?php the_ID(); ?>">


//////////////loop


<?php endwhile; else: ?><div class="post_class"><a href=" ">No results</a></div><?php endif; ?></ul></div></div><p>&nbsp;</p></div></div>

Answers (3)

2013-06-01

Arnav Joy answers:

you can do it like

<?php

if ($current_user->phone == 'iphone5')
$cat_id = 1065;
else if ($current_user->phone == 'galaxys3')
$cat_id = 824;
else if ($current_user->phone == 'galaxys4')
$cat_id = 1179;

query_posts(array( 'showposts'=>6,'cat' => $cat_id ,'orderby' => 'meta_value_num','meta_key' => 'sales_count','order' => 'DESC', ));?>


change $cat_id variable's value and if condition's phone name


monitor comments:

Yes, that seemed to work. Thanks

2013-06-01

Yakir Sitbon answers:

What?
Are you want loop all users with custom field iphone == 'iphone5'?

2013-06-01

Abdelhadi Touil answers:

Hi.
You can use this code inside loop:

<?php
$user_iphone = get_the_author_meta('iphone5');
if ($user_iphone != ''){ ?>
<img src="<?php bloginfo('template_directory'); ?>/profile/img/ip5.png" alt="ip5" />
<?php } ?>


Good luck.