WordPress.org

Forums

Buddypress Xprofile Custom Fields Type
[resolved] Get posts by xprofile field (9 posts)

  1. applegateian
    Member
    Posted 2 years ago #

    Hi guys

    All of the users on my site will be required to choose a custom xprofile type called ‘account type’ when they register.

    There are 5 different types.

    Each user can create standard WordPress posts that appear on a top level page called ‘posts’.

    I need to filter ‘posts’ further, by these 5 user types to run 5 separate WordPress pages. These would be posts by these authors, filtered by their different xprofile paths.

    How can I query by the Xprofile field?

    Many thanks,

    Ian

    http://wordpress.org/extend/plugins/buddypress-xprofile-custom-fields-type/

  2. donmik
    Member
    Plugin Author

    Posted 2 years ago #

    I've been looking for an answer and I don't know one easy...

    For now, if I were in your situation, I would filter first the authors using something like BP Profile Search plugin http://wordpress.org/extend/plugins/bp-profile-search/. In this plugin, we can search members looking in xprofiles fields.

    With this, we obtain the user_id of the authors and you can use it to make a query of posts written by these authors. Maybe there is another way but I couldn't find it.

  3. valuser
    Member
    Posted 2 years ago #

    Try this it just might work! if i have understood you correctly!

    1) put this into functions.php or ……

    function include_by_meta($theMetaValue, $theMetaField) {
    
    	$memberArray = array();
    
    global $members_template;
    
    		if (bp_has_members()) :
    
    		while (bp_members()) :
    
    			bp_the_member();
    
    			$theFieldValue = bp_get_member_profile_data( 'field='. $theMetaField );
    
    			if ($theFieldValue==$theMetaValue) {
    
    				array_push($memberArray, bp_get_member_user_id());
    
    			}
    
    		endwhile;
    
    		endif;
    
    	$theIncludeString=implode(",",$memberArray);
    
    	return $theIncludeString;
    
    }

    2) Make your pages ---- copy members-loop into each page account_type_1, account_type_2, etc

    And

    begin each page

    <?php do_action( 'bp_before_members_loop' ); ?>
    <?php if ( bp_has_members( bp_ajax_querystring( 'members' ) ) ) : ?>
    <?php $yvar= "account_type_1";  if (bp_has_members( array( 'include' => include_by_meta($yvar,'account_type'), 'type' => 'newest') )) : ?>

    etc etc

    don't forget the endif

    <span class="update"> <?php bp_member_latest_update(); ?></span>
    <?php endif; ?>

    Cheers and hoping it works

  4. valuser
    Member
    Posted 2 years ago #

    i have assumed your bp xprofile field is account_type

  5. valuser
    Member
    Posted 2 years ago #

    obviously replace account_type_1 with account_type_2 etc

  6. mikegarlick
    Member
    Posted 2 years ago #

    I am looking to do something similar.

    I want to be able to filter a custom post post type with the details provided in the xprofile. The problem i have is that the data field i want to search by has many things in them.

    What im making is a custom post type of jobs advertised on the site and when they get to the site i nead to search the posts custom fields or tags with the xprofile data field.

    I hope that makes sense

  7. donmik
    Member
    Plugin Author

    Posted 2 years ago #

    Sorry to answer so late, I'm kind of busy lately.

    Mmm, I think I understand. For example, you can have custom post type of jobs in London and you want to show them when a user from London is logged in.

    Well, for the custom posts types you can use tags or maybe Types plugin (Great plugin!). With this code, you can get any data from profile field of the current logged in user:

    global $bp;
    $your_data = bp_get_profile_field_data('field=nameofprofilefield&user_id='.bp_loggedin_user_id());

    Next thing to do is to filter your custom posts types using this data.

  8. mikegarlick
    Member
    Posted 2 years ago #

    Brilliant! thank you for the reply. I'll let you know how i get on!

  9. donmik
    Member
    Plugin Author

    Posted 2 years ago #

    Ok, I think this is solved now...

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Buddypress Xprofile Custom Fields Type
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic