BuddyDev

Search

Replies

  • Participant
    Level: Initiated
    Posts: 7
    Melanie on #52402

    *Update*

    After checking a lot on Google I came across this term “sync”, so maybe I explained it wrong or used the wrong terminology (my apologies).

    So let me try again, I try to sync ACF fields with the xprofile fields created.

    Example: if a user registers with his country, then country will show up in his user profile page via xprofile field.

    If I create a ACF field with the same name now, can I sync the xprofile data/value with the ACF field?

    I hope this time this is clearer than using transfer or other words to describe what I am trying to achieve 😉

  • Participant
    Level: Initiated
    Posts: 7
    Melanie on #52398

    Hi Brajesh,
    once again I really appreciate your input 😉

    My goal is to create a ACF field with the name e.g. “Country”.
    Now I already created xprofile field with teh same name. A user registers and fill sout the xprofile field.
    So, how can I make the ACF field have the same value now?

    Example: user registers via BB registration form and enters his country (xprofile field): Argentina. So the xprofile field shows “Argentina”.

    Now, lets say I create a separate ACF field also called “Country”.
    How can I make “Argentina” from the xprofile field now show up in the ACF field?

    Is there a code snippet to make this happen?

    Reason for this question: if I can create ACF fields then I can get a meta key which I can then use for more functions and plugins.

  • Participant
    Level: Initiated
    Posts: 7
    Melanie on #52394

    Hi Brajesh,

    thanks – I installed the plugin and tried the 2 shortcodes:
    [bpsc-profile-data] as well as
    [bpc-profile-data] but they both do not work.

    Nothing shows up on the page.

    Without meta keys there is no real way to transfer the xprofile values to Elementor or any other 3rd party plugin.
    Is there a way to add meta keys to each of the xprofile fields?

    (It would be less of a problem if I could at least also show the xprofile field values in ACF counterpart fields, so transfer/map xprofiel field data to ACF fields)

    • This reply was modified 7 months, 2 weeks ago by Melanie.
  • Participant
    Level: Initiated
    Posts: 7
    Melanie on #51681

    Hi Ravi, sure no worries 😉

    FYI, I tried a bit more things. I told you that I added the additional filter to the filter dropdown (recently active, newest and alphabetical) via: bp_members_directory_order_options

    I also tried to add it the same way as a tab instead like you add the tabs for “Featured Members” or “Recent Visitors” via: bp_members_directory_member_types

    All I want is this: have a new filter option to additionally filter the results. So lets say I check the Recent visitor or featured members tabs and see the results. They are not filtered yet, random, they show all members falling into the category (so either featured members or recent visitor based on what tab I selected).

    Now I want to filter them on top, to show for example only those whose name starts with an “A” as I previously mentioned. But this is where I am lost.

    I tried to hook into several options: bp_before_directory_members_content, bp_after_directory_members_content, bp_after_has_members_parse_args, bp_after_members_loop, etc but nothing worked.

  • Participant
    Level: Initiated
    Posts: 7
    Melanie on #51660

    Hi Ravi,
    sorry seems my 2nd message with the code did not get sent.
    Yes, these filter options are the native filter options we get:
    ‘active’, ‘random’, ‘newest’, ‘online’ and ‘alphabetical’.
    What I tried to achieve was to add a new one. Or if its not possible to add a new filter option in this dropdown I would also be happy to show it as a tab (next to “All Members”, “Recent Visitors” or “Featured Members” tabs) on the members page.

    But lets go back to what I was trying to do. So I added a filter option into the dropdown to the others:

    ` // Function to add the “Only A” filter option
    function add_only_a_filter() {
    ?>
    <option value=”only_a”><?php _e( ‘Only A’, ‘buddypress’ ); ?></option>
    <?php
    }

    // Hook to add the “Only A” filter option to the Members directory order options
    add_action( ‘bp_members_directory_order_options’, ‘add_only_a_filter’ ); `

    The new filter option called “only A” shows up in the dropdown, so far so good. It is supposed to filter the results of any other search be it All Members, BP Search form results or even the Recent Visitor or Featured Member results to show only users whose name starts with an “A”.

    The filter shows up inside the dropdown but when I try to add a logic, it automatically filters alphabetically rather than showing me only those members whose name starts with an “A”.

     // Function to modify the members query based on the selected filter
    function modify_members_query_for_only_a( $query_args ) {
        if ( isset( $_GET['members_filter'] ) && $_GET['members_filter'] === 'only_a' ) {
            $query_args['field_id'] = '1'; // Adjust 'field_1' to the actual first name field key
            $query_args['meta_value'] = 'A%';
        }
        return $query_args;
    }
    
    // Hook to apply the filter to the members query
    add_filter( 'bp_after_has_members_parse_args', 'modify_members_query_for_only_a' ); 

    The field ID 1 is the First name field that I want to check who starts with “A”.
    I read in some of BuddyDevs older posts that its a good idea to hook into “‘bp_after_has_members_parse_args'” – which is what I was trying to do. I was hoping that by adding this filter logic the new filter option would show me users whose name starts with “A”.

    If this approach does not work, is there any way to add a separate tab maybe that might let me filter the results for other thiings than just alphabetical or recently active etc?

    Thanks again, Ravi 😉