Replies
Dear Brajesh,
Sorry, I am not a developer so some terms i have to look up.
Initializing a variable means giving it a value, right? Like $collection_term = ‘foo’;I am looking to get taxonomyterm values by user, and for each value create a subnav tab.
In any case the first step to achieve that is to be able to use a variable from outside the function.I have placed below code in bp-custom.php, but without any result. I have also tried to use $GLOBALS[‘collection_term’], but also no result there.
$collection_term = 'test'; function my_custom_subnav() { global $bp; global $collection_term; $collection_term_slug = strtolower($collection_term);//lowercase $collection_term_slug = preg_replace('/\s+/', '-', $collection_term); // replace spaces with hyphens. $collection_term_slug = preg_replace('/[^A-Za-z0-9\-]/', '', $collection_term); // Removes special chars. $screen_function_name = 'subnav_function_to_show_' . $collection_term_slug; bp_core_new_subnav_item( array( 'name' => $collection_term, 'slug' => $collection_term_slug, 'screen_function' => 'screen_function_name', 'parent_url' => trailingslashit( bp_displayed_user_domain() . 'collections' ), 'parent_slug' => 'collections', 'position' => 100, ) ); }
I have hired some developers look at the code, and try to implement what i am looking to achieve, but they have been unsuccesful in their task. By the way, i read somewhere that global variables will be depreciated in php6.
Your help is highly appreciated! Would it be possible to hire you to implement the code?
- This reply was modified 8 years, 11 months ago by eGuard.
Hi Brajesh,
I can’t seem it to get to work.
I managed to get the id’s ofthe members i want to display, and I managed to pass the id’s to the query.
I tried elow to show the avatar (for testing to make sure id’s are passed correctly) it works fine
if ( bp_has_members( ‘include=’ . $ids_implode) ) : ?> <?php while ( bp_members() ) : bp_the_member(); ?> <?php bp_member_avatar(‘type=full&width=125&height=125′) ?> <?php endwhile; ?> <?php endif; ?><?
However when i want to call the template it doesn’t seem to work
if ( bp_has_members( ‘include=’ . $ids_implode) ) : ?> <?php while ( bp_members() ) : bp_the_member(); ?> <?php bp_get_template_part( ‘members/members-loop’ ); ?> <?php endwhile; ?> <?php endif; ?><?
What am i missing here?
- This reply was modified 9 years, 1 month ago by eGuard.
Thanks for your reply.
What is seems to do is get the terms and a link, right?
That is not what i was actually asking your help for. what i was looking to achieve is to create a subnav tab for each term in the buddypress member profile view.
so by looping functions my_custom_subnav(), function subnav_function_to_show_screen_title() and
function subnav_function_to_show_screen_content() for each term the user has used within the custom taxonomy.nav tab: collection (default fixed profile tab)
sub nav tab: term1, term3, term 4, term7 (depending on the terms the user has used in the submitted posts)I hope that clarifies what i am looking to achieve.
Hi Brajesh,
1) Yes, a term can be used by more than 1 user
2) Also correct, ONLY the terms used by the displayed userThe code above (GET COLLECTIONS TAXONOMY TERMS) gets only the terms used by the displayed user.
return array_unique($author_terms);
And i am looking to loop this array and create a subnav tab for each term in this array.
Sorry,
one last question in regards to this subject.
Based on your example, i have created a function where i can specify the member type
function get_user_id_by_member_types( $ids = array(), $type ){ $ids = wp_parse_id_list( $ids ); if( ! $ids ) { return ; } $args = array( 'user_ids' => $ids, 'populate_extras' => true, //it will fetch names etc and cache member types ); $user_query = new BP_User_Query( $args ); $users = $user_query->results; $user_by_types = array();//multidimensional array //an Arr of WP_User objects with some added details like last_activity, latest_update etc foreach ( $users as $user ) { $member_type = bp_get_member_type( $user->ID ); if( ! $member_type ) { continue; } $user_by_types[$member_type][] = $user->ID; } // print_r( $user_by_types ); $type_result = $user_by_types[$type]; //print_r ($type_result); $csv = implode( ',' , $type_result ); echo $csv; }
It echo’s a comma seperated list of ID’s for the type.
Your member type generator plugin can also have a member directory for each member type.
What i would like to do is to have a member directory (just like yours) in a navigation tab in the displayed user profile.So i have created a nav tab called “students”, and as content of the nav tab i would like to have the directory of all users in the array $csv of the type students as defined in $type.
I know where to put the content code for this tab, but i don’t know how to query the memberloop for both the $type (in this case students) and the ID’s in $csv.
Could you give me a pointer in the right direction?
Hi Brajesh,
I have tested the (counting) code and it seems to be working. However, it returns a total count of all members.
What was after is to get the results for a specific array of user ID’s, and breakdown this array:
E.g.
$res2 = array(1,2,3,4,5,6,7,8,9,10,11)
4 teachers, ID’s 1,2,3,4
5 students, ID’s 5,6,7,8,9
2 parents, ID’s 10,11so i need a way to tell your function to only check the ID’s as in $res2