BuddyDev

Search

Check how many favourites the displayed user has / display a link if zero

  • Participant
    Level: Enlightened
    Posts: 35
    Kir on #26052

    Hi

    How would I check the db to see how many featured items have been selected by a user?

    Any pointers would be greatly appreciated –

    I want to say that when you’re looking at a displayed user, if 1,2, 3 or 4 featured items have been selected by that user, then this code should run showing 2 posts on that displayed user’s profile:

    <td style="width: 23%;">
    			<div id="item-header-events"><?php echo do_shortcode ( '[su_posts posts_per_page="2" template="posts-templates/my-loop.php" post_type="product" order="desc" author="'. bp_displayed_user_id() .'"]' );?>
    		</div>

    But if 5, 6, 7 or 8 featured items have been selected by the displayed user, then the same code should run but instead displaying 4 posts on that user’s profile:

    <td style="width: 23%;">
    			<div id="item-header-events"><?php echo do_shortcode ( '[su_posts posts_per_page="4" template="posts-templates/my-loop.php" post_type="product" order="desc" author="'. bp_displayed_user_id() .'"]' );?>
    		</div>

    And if no featured items have been selected as featured by the user you’re displaying, whether you or someone ese, then should run:

    <td style="width: 23%;">
    			<div id="item-header-events"><?php echo do_shortcode ( '[su_posts posts_per_page="1" template="posts-templates/my-loop.php" post_type="product" order="desc" author="'. bp_displayed_user_id() .'"]' );?>
    		</div>

    And if user profile is yours also:
    ‘echo “Please feature your favourite images here‘ (This could be a good feature for the plugin, actually…)

    But if user profile is someone else’s display nothing in the header

  • Participant
    Level: Enlightened
    Posts: 35
    Kir on #26053

    I don’t seem to be able to edit the above although there’s an edit link, but just to add that this is in relation to Media Press Featured Content
    Thank you 🙂

  • Keymaster
    (BuddyDev Team)
    Posts: 24501
    Brajesh Singh on #26058

    Hi Kir,
    There are no direct methods to do the count. You may use this though.

    
    
    $count = count( mppftc_get_featured_media( 'component_id' => $user_id, 'per_page'=> -1 ) );
    
    

    That should most probably give the count. You will need to update the $user_id.

    Internally, featured media are simply ‘attachment’ post type with meta ‘_mppftc_featured’ set to 1. You can do a direct count for efficiency.

    Regards
    Brajesh

You must be logged in to reply to this topic.

This topic is: not resolved