• Resolved slykereven

    (@slykereven)


    Hello,
    I have created a custom theme for the directory of listed members, it works well, but I would like to display an image in addition depending on the value of a custom field, for example :
    If meta_key_mycustomfield_value == "shopping" then echo <img src="..." />

    I don’t see how to find the value of this custom field …
    If someone has an idea how to do this ? Thanks

    • This topic was modified 3 years, 9 months ago by slykereven.
    • This topic was modified 3 years, 9 months ago by slykereven.
    • This topic was modified 3 years, 9 months ago by slykereven.
Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @slykereven

    I’m sorry but it’s not clear what you want to achieve. Could you please explain in greater details? Also, please provide the code so we can review it?

    Regards,

    Thread Starter slykereven

    (@slykereven)

    Hi @champsupertramp ,
    I’ve got this custom field
    https://imgur.com/KZe7lDm
    In the custom template for directory members, I would like to display an image, something like:
    if meta_key_secteur_activite = "Agriculture" then echo <img src="..." />

    <?php /* Template: List 2 */
    if ( ! defined( 'ABSPATH' ) ) exit;
    
    $unique_hash = substr( md5( $args['form_id'] ), 10, 5 ); ?>
    
    <script type="text/template" id="tmpl-um-member-list-<?php echo esc_attr( $unique_hash ) ?>">
    	<div class="um-members um-members-list">
    
    		<# if ( data.length > 0 ) { #>
    			<# _.each( data, function( user, key, list ) { #>
    
    				<div id="um-member-<code>user.card_anchor</code>-<?php echo esc_attr( $unique_hash ) ?>" class="um-member um-role-<code>user.role</code> <code>user.account_status</code> <?php if ( $cover_photos ) { echo 'with-cover'; } ?>" style="padding: 0;">
    					<span class="um-member-status <code>user.account_status</code>">
    						<code>user.account_status_name</code>
    					</span>
    					<div class="um-member-card-container" style="background-color: #104f6f; margin-bottom: 0px;">
    <strong>!!!!! HERE THE PLACE FOR THE CUSTOM CODE !!!!!
    if meta_key_secteur_activite == "Agriculture" then echo <img src="..." /></strong>
    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @slykereven

    You need to add the metakey and value to bind in the member directory with the following code snippet:

    add_filter("um_ajax_get_members_data","um_profile_avatar_members_data", 10, 3 );
    function um_profile_avatar_members_data( $data_array, $user_id, $directory_data ){
    
        um_fetch_user( $user_id );
        $data_array['secteur_activite'] = um_user('secteur_activite');
    
        return $data_array;
    
    }

    And then to bind the sectuer_activite value, you can try this code:

    <# if ( data.secteur_activite == "Agriculture" ) { #>
         <code>data.secteur_activite</code>
         <img src="test.jpeg"/>
    <# } #>

    Regards,

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @slykereven

    Please feel free to re-open this thread by changing the Topic Status to ‘Not Resolved’ if any other questions come up and we’d be happy to help. ??

    Regards,

    Thread Starter slykereven

    (@slykereven)

    Hi @champsupertramp,
    Sorry I didn’t see the update of the topic before, so I try your code, it seems to be the function I’m searching but can’t have it works … See below my code :

    <div class="um-member-card-header">
    									<?php if ( $show_name ) { ?>
    										<div class="um-member-name" style="justify-content: center;">
    											<a href=&quot;<code>user.profile_url'
    &quot; title=&quot;'user.display_name'&quot; style=&quot;color: #ffffff; text-align: center; font-weight: 400;&quot;>
    												'user.display_name_html'
    											</a>
    										</div>
    									<?php } ?>
    									<?php
    									add_filter(&quot;um_ajax_get_members_data&quot;,&quot;um_profile_avatar_members_data&quot;, 10, 3 );
    									function um_profile_avatar_members_data( $data_array, $user_id, $directory_data ){
    
    										um_fetch_user( $user_id );
    										$data_array['secteur_activite'] = um_user('secteur_activite');
    
    										return $data_array;
    
    									} ?>
    									<# if ( data.secteur_activite == &quot;Epicerie Fine&quot; ) { #>
    										 'data.secteur_activite'
    										 <img src="&quot;test.jpeg&quot;" />
    										 <div>OK</div>
    									<# } #>

    I’m testing on a page where i’m sure a member has a metakey : secteur_activite = “Epicerie Fine”
    If you have any hint to make it works ? Thanks

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @slykereven

    Your code encoding is messed up. Please check or use https://gist.github.com/ to share your code here.

    Regards,

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @slykereven

    Please feel free to re-open this thread by changing the Topic Status to ‘Not Resolved’ if any other questions come up and we’d be happy to help. ??

    Regards,

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Display custom field in a custom template members directory’ is closed to new replies.