Skip to content

Instantly share code, notes, and snippets.

@nicdford
Last active November 23, 2019 20:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicdford/f3b70d756414d3f3731f to your computer and use it in GitHub Desktop.
Save nicdford/f3b70d756414d3f3731f to your computer and use it in GitHub Desktop.
A custom shortcode that makes a pods query and returns the value when the shortcode is called.
// Display Wine Items
function cc_display_wine( $atts ) {
// Attributes
extract( shortcode_atts(
array(
'wine_id' => '1',
), $atts )
);
$wine_id = $atts['wine_id'];
$wine = pods( 'wine', $wine_id );
$wine_image = pods_image( $wine->field('product_image'), 'full' );
$wc = '<div class="wine-feature-contain">';
$wc .= $wine_image;
$wc .= '<div class="wine-feature-content hide">';
$wc .= '<h4 class="sub-title">' . $wine->field( 'subtitle' ) . '</h4>';
$wc .= '<h2 class="title">' . $wine->field( 'name' ) . '</h2>';
$wc .= '<p>' . $wine->field( 'product_description' ) . '</p>';
$wc .= '<a class="btn" href="' . $wine->field('op_url') . '" alt="' . $wine->field('name') . '" title="' . $wine->field('name') . '">Purchase</a>';
$wc .= '</div>';
$wc .= '</div>';
return $wc;
}
add_shortcode( 'display_wine', 'cc_display_wine' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment