Add user meta to a view

Est. Reading: 1 minute
By: mjmaso
Created: 12/20/2016
Category:
Difficulty: Intermediate

Add user meta to a view

×Warning: This tutorial was created 2893 days ago. Some of the information may be out of date with more recent versions of Formidable. Please proceed with caution and always perform a backup before adding custom code.

/** Formidable hook - shortcode view user meta */
add_shortcode( 'view_meta', 'view_meta_shortcode' );

function view_meta_shortcode( $atts ) {

$atts = shortcode_atts(
array(
'user' => '',
'meta' => '',
), $atts, 'view_meta' );

$results = get_user_meta ($atts['user'],$atts['meta'], true);

return $results;
}

/** Formidable hook - shortcode conditionaly view user meta */
add_shortcode( 'if_view_meta', 'if_view_meta_shortcode');

function if_view_meta_shortcode( $atts, $content = '' ) {
$atts = shortcode_atts(
array(
'user' => '',
'meta' => '',
), $atts, 'if_view_meta' );

$results = get_user_meta ($atts['user'],$atts['meta'], true);

if ( $results ) {
return $content;
} else {
return;
}
}

Leave a Reply

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crosschevron-leftchevron-rightarrow-right