Skip to:
Content
Pages
Categories
Search
Top
Bottom

Order activity loop by meta value


  • haitianguy
    Participant

    @haitianguy

    Hi, i feel like im doing this properly but i never get the right result. i have a custom meta called “featured” in activity meta. For testing purposes the meta values are 1,2,3,4 my goal is to have an activity loop order activities by the meta value. i’ve checked the documentation and i came up with this.

    
    <?php
    
    get_header(); ?>
    
    <?php get_template_part('page-parts/general-title-section'); ?>
    
    <?php get_template_part('page-parts/general-before-wrap');
    
    $atts =  array(
    			'title'            => 'Latest Activity',// title of the section.
    			'pagination'       => 1,// show or not.
    			'load_more'        => 0,
    			'display_comments' => 'threaded',
    			'include'          => false,     // pass an activity_id or string of IDs comma-separated
    			'exclude'          => false,     // pass an activity_id or string of IDs comma-separated
    			'in'               => false,     // comma-separated list or array of activity IDs among which to search
    			'sort'             => 'DESC',    // sort DESC or ASC
    			'page'             => 1,         // which page to load
    			'per_page'         => 5,         // how many per page.
    			'max'              => false,     // max number to return.
    			'count_total'      => true,
    
    			// Scope - pre-built activity filters for a user (friends/groups/favorites/mentions).
    			'scope'            => false,
    
    			// Filtering
    			'user_id'          => false,    // user_id to filter on
    			'object'           => false,    // object to filter on e.g. groups, profile, status, friends
    			'action'           => false,    // action to filter on e.g. activity_update, new_forum_post, profile_updated
    			'primary_id'       => false,    // object ID to filter on e.g. a group_id or forum_id or blog_id etc.
    			'secondary_id'     => false,    // secondary object ID to filter on e.g. a post_id.
    
    			// Searching
    			'search_terms'     => false,         // specify terms to search on.
    			'use_compat'       => bp_use_theme_compat_with_current_theme(),
    			'allow_posting'    => false,    // experimental, some of the themes may not support it.
    			'container_class'  => 'activity',// default container,
    			'hide_on_activity' => 1,// hide on user and group activity pages.
    			'for'              => '', // 'logged','displayed','author'.
    			'role'             => '', // use one or more role here(e.g administrator,editor etc).
                'for_group'        => '',// group slug.
    		);
    
    		$atts['meta_query']= array(
                                        array(
                                            'key' => 'featured',
                                            'value' => '0',
                                            'type' => 'numeric',
                                            'compare' => '!=',
                                            ),
                                            'meta_type' => 'numeric',
                                    'orderby' => 'meta_value_num',
                                    'meta_key' => 'featured',
                                    'order' => 'DESC'
                                    );
    
     ?>
    			<div id="buddypress">
    	
    
    		<?php do_action( 'bp_before_activity_loop' ); 
    		
    		
    		
    	
    
    if ( bp_has_activities( $atts ) ) : ?>
    
                <div class="<?php echo esc_attr( $atts['container_class'] ); ?> 
                <?php if ( ! $atts['display_comments'] ) : ?> hide-activity-comments<?php endif; ?>">
    
                    <ul id="activity-stream" class="activity-list item-list">
    
    					<?php while ( bp_activities() ) : bp_the_activity(); ?>
    						
    						<?php bp_get_template_part( 'buddypress/activity/entry' ); ?>
    					<?php endwhile; ?>
    
    					<?php if ( $atts['load_more'] && bp_activity_has_more_items() ) : ?>
                            <li class="load-more">
                                <a href="<?php bp_activity_load_more_link() ?>"><?php _e( 'Load More', 'buddypress' ); ?></a>
                            </li>
    					<?php endif; ?>
                    </ul>
    
    				<?php if ( $atts['pagination'] && ! $atts['load_more'] ) : ?>
                        <div class="pagination">
                            <div class="pag-count"><?php bp_activity_pagination_count(); ?></div>
                            <div class="pagination-links"><?php bp_activity_pagination_links(); ?></div>
                        </div>
    				<?php endif; ?>
    
                </div> 
    
            <?php else : ?>
                <div id="message" class="info">
                    <p><?php _e( 'Sorry, there was no activity found. Please try a different filter.', 'buddypress' ); ?></p>
                </div>
            <?php endif; ?>
            
    ?>
    			</div>
    		
    
    		<?php do_action( 'bp_after_activity_loop' ); ?>
    
    <?php get_template_part('page-parts/general-after-wrap'); ?>
    
    <?php get_footer(); ?>
    

    everything here works except for the order. for some reason it always orders by activity ID. am i missing something here? Thanks in advance im going crazy with this.

  • You must be logged in to reply to this topic.
Skip to toolbar