Display same fields as member directory on member swap cards

Home Forums Gwangi – Dating & Matchmaking Community Theme Popular Features Member Swap Display same fields as member directory on member swap cards

This topic contains 5 replies, has 2 voices, and was last updated by  Themosaurus 6 months, 2 weeks ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #4855

    Malas Reda
    Participant
    • 15 Posts
    @malasreda

    Hey,

    I have found another issue regarding the members swap page, the profile card does not show the same items as on the search results like matching hearts on the right bottom corner and other fields.

    I have used the snippet plugin to show some fields on the members page but does not appear on the swap members page. How can i make them appear as well as the matchmaking button ?

    Best regards,

    #4865

    Themosaurus
    Keymaster
    • 1674 Posts
    @themosaurus

    Hi @malasreda,

    1. For the matching button on the member swap, good timing because we have just release a new version of Gwangi (v 1.1.9) that adds the matching button in the member swap view!

    To update your theme, you can download and install the Envato Market plugin (https://envato.com/market-plugin/) on your WordPress site.

    Once the plugin is installed and activated, go to “Envato Market” in your admin menu and follow the instructions under “Activate Envato API Connection”.

    When this is done, you will see your purchased themes under the “Themes” tab and you should be able to update your Gwangi theme from there by clicking the “Update available” button.

    Also, don’t forget to update your child theme if you are using one, and update all of our Grimlock plugins to their latest versions.

    2. For the member fields, can you send us the code snippet that you used to display your member fields in the member directory? That way we can take a look and try to find why they are not displayed on the member swap page.

    Regards

    #4881

    Malas Reda
    Participant
    • 15 Posts
    @malasreda

    hello,

    By updating the theme, the fileds also appeared in the swap section ! Wich is great !

    But when i add a codeWhen i add a code snippet to display the member age on the member directory, it shows the date format d/m/year.

    How can i show only the age not the date ?

    Thank you

    #4899

    Themosaurus
    Keymaster
    • 1674 Posts
    @themosaurus

    Hi @malasreda,

    This is great news 🙂

    Right now you are directly displaying the birthdate instead of the age. Here is a code snippet that should display the age:

    if ( ! function_exists( 'gwangi_buddypress_member_birthdate' ) ) :
    	/**
    	 * Print the HTML for the Birthdate XProfile Field in the BP Member Directory.
    	 *
    	 * @since 1.0.0
    	 */
    	function gwangi_buddypress_member_birthdate() {
    		if ( function_exists( 'xprofile_get_field_data' ) ) :
    
    			$birthdate_field_id = xprofile_get_field_id_from_name( 'Birthdate' );
    
    			if ( ! empty( $birthdate_field_id ) ) :
    				$birthdate                = xprofile_get_field_data( $birthdate_field_id, bp_get_member_user_id() );
    				$birthdate_field_settings = BP_XProfile_Field_Type_Datebox::get_field_settings( $birthdate_field_id );
    
    				if ( 'elapsed' !== $birthdate_field_settings['date_format'] ) :
    					$birthdate_datetime = DateTime::createFromFormat( $birthdate_field_settings['date_format'], $birthdate );
    					if ( ! empty( $birthdate_datetime ) ) :
    						$age = $birthdate_datetime->diff( new DateTime( 'now' ) )->y;
    					endif;
    				endif;
    
    				$allowed_html = array(
    					'a' => array(
    						'href' => array(),
    						'rel'  => array(),
    					),
    				);
    				if ( ! empty( $age ) ) : ?>
    					<div class="bp-member-xprofile-custom-field bp-member-birthdate"><?php echo wp_kses( $age, $allowed_html ); ?></div>
    				<?php
    				endif;
    			endif;
    		endif;
    	}
    endif;

    Don’t forget to change 'Birthdate' with your own field name. If you replace your snippet by that one, it should do the trick.

    Regards,

    #4916

    Malas Reda
    Participant
    • 15 Posts
    @malasreda

    Thank you it works.

    On the profile page, profile informations how can i show the age rather than the date ?

    #4936

    Themosaurus
    Keymaster
    • 1674 Posts
    @themosaurus

    Hi @malasreda,

    Glad we could help 🙂

    Here is another code snippet that should do the trick:

    add_filter( 'bp_get_the_profile_field_name', 'gwangi_change_birthdate_field_name' );
    function gwangi_change_birthdate_field_name( $field_name ) {
    
    	if ( $field_name === 'Birthdate' && bp_is_user_profile() && ! bp_is_user_profile_edit() ) {
    		return 'Age';
    	}
    
    	return $field_name;
    }
    
    add_filter( 'bp_get_the_profile_field_value', 'gwangi_change_birthdate_field_value', 10, 3 );
    function gwangi_change_birthdate_field_value( $value, $type, $id ) {
    
    	$field = xprofile_get_field( $id );
    
    	if ( ! empty( $field ) && $field->name === 'Birthdate' ) :
    		$birthdate                = $value;
    		$birthdate_field_settings = BP_XProfile_Field_Type_Datebox::get_field_settings( $id );
    
    		if ( 'elapsed' !== $birthdate_field_settings['date_format'] ) :
    			$birthdate_datetime = DateTime::createFromFormat( $birthdate_field_settings['date_format'], $birthdate );
    			if ( ! empty( $birthdate_datetime ) ) :
    				$value = $birthdate_datetime->diff( new DateTime( 'now' ) )->y;
    			endif;
    		endif;
    	endif;
    
    	return $value;
    }

    Once again, please don’t forget to change Birthdate by your own field name and Age by the name you want to display instead of Birthdate.

    Regards,

Hi there,

This topic has been inactive for a while now so we will be closing it to keep the forum tidy. Don't hesitate to create a new topic if you still need help and we'll be glad to help you!

Best regards,
The Themosaurus team.

Viewing 6 posts - 1 through 6 (of 6 total)

The topic ‘Display same fields as member directory on member swap cards’ is closed to new replies.