Tags: News

Dynamic Tags from repeater

Date: May 4, 2026

/**
* Shortcode to extract a repeater image from a JetEngine repeater field.
*
* Usage examples:
* [ra_repeater_image post_id=”123″ field=”speakers” index=”0″ subfield=”photo” size=”medium”]
* [ra_repeater_image field=”gallery” index=”2″ subfield=”image” size=”full” return=”url”]
* Args:
* post_id — defaults to current post (omit inside listings/single)
* field — repeater meta key on the post (required)
* index — row index, 0-based (default 0)
* subfield — image subfield key inside the row (required)
* size — image size: thumbnail|medium|large|full (default ‘full’)
* return — ‘url’ (default) or ‘html’ (img tag with alt)
* fallback — image URL to use if missing
*/

add_shortcode( ‘ra_repeater_image’, function( $atts ) {
$atts = shortcode_atts( array(
‘post_id’ => 0,
‘field’ => ”,
‘index’ => 0,
‘subfield’ => ”,
‘size’ => ‘full’,
‘return’ => ‘url’,
‘fallback’ => ”,
), $atts, ‘ra_repeater_image’ );

$post_id = absint( $atts[‘post_id’] ) ?: get_the_ID();
if ( ! $post_id || empty( $atts[‘field’] ) || empty( $atts[‘subfield’] ) ) {
return esc_url( $atts[‘fallback’] );
}

$rows = get_post_meta( $post_id, $atts[‘field’], true );
if ( ! is_array( $rows ) ) {
$rows = json_decode( $rows, true ); // JE may store JSON strings
}
if ( ! is_array( $rows ) ) {
return esc_url( $atts[‘fallback’] );
}

// Re-key in case stored as object-style array.
$rows = array_values( $rows );
$index = absint( $atts[‘index’] );
if ( ! isset( $rows[ $index ] ) ) {
return esc_url( $atts[‘fallback’] );
}

$row = $rows[ $index ];
$val = isset( $row[ $atts[‘subfield’] ] ) ? $row[ $atts[‘subfield’] ] : ”;

// JE Media field can store: attachment ID (int), URL (string), or array {id, url}.
$url = ”;
$id = 0;
if ( is_numeric( $val ) ) {
$id = (int) $val;
$url = wp_get_attachment_image_url( $id, $atts[‘size’] );
} elseif ( is_array( $val ) ) {
$id = isset( $val[‘id’] ) ? (int) $val[‘id’] : 0;
$url = isset( $val[‘url’] ) ? $val[‘url’] : ”;
if ( $id && $atts[‘size’] !== ‘full’ ) {
$url = wp_get_attachment_image_url( $id, $atts[‘size’] ) ?: $url;
}
} elseif ( is_string( $val ) && $val ) {
$url = $val;
$id = attachment_url_to_postid( $val );
if ( $id && $atts[‘size’] !== ‘full’ ) {
$url = wp_get_attachment_image_url( $id, $atts[‘size’] ) ?: $url;
}
}

if ( ! $url ) {
return esc_url( $atts[‘fallback’] );
}

if ( ‘html’ === $atts[‘return’] ) {
$alt = $id ? esc_attr( get_post_meta( $id, ‘_wp_attachment_image_alt’, true ) ) : ”;
return sprintf( ‘%s‘, esc_url( $url ), $alt );
}

return esc_url( $url );
} );

Related News

Date: May 4, 2026
Event Speakers for RA Event Listing
Date: May 4, 2026
Event Speakers for RA Event Listing
Date: May 3, 2026
Single Page for RA Event - Page
Date: May 2, 2026
RA Event Category Archive