Sure! Here's how you can use PHP to dynamically set the background image for each .it_staff_section based on your repeater field inside a Listing Item or your template.
Assumptions
- You have a repeater field
it-staff-repeater on the post (or CPT).
- Each repeater item has subfields
it_staff_image (Media/Image ID or URL) and it_staff_title.
- Your Listing Item template outputs a wrapper
<section class="it_staff_section">...</section> for each repeater item.
- You want to output inline CSS — per section — that uses the repeater image as the background image.
Steps to do this with PHP:
1. Modify your Listing Item or template file
You need to modify the output so each section has a unique identifier or key, so you can target it via CSS.
For example, modify your section element and add a unique ID or data attribute:
<?php
// Get current repeater index (depends on listing or loop implementation)
// Assuming you're looping over the repeater items with index $index.
$index = /* your current index, usually from foreach or loop */;
$repeater = jet_engine()->listings->data->get( 'it-staff-repeater' );
// or use jet-engine function to get repeater data
$image = jet_engine()->listings->data->get( 'it_staff_image', $index );
$image_url = '';
if ( is_numeric( $image ) ) {
$image_url = wp_get_attachment_image_url( $image, 'full' );
} elseif ( filter_var( $image, FILTER_VALIDATE_URL ) ) {
$image_url = $image;
}
?>
<section
class="it_staff_section"
id="it_staff_section_<?php echo esc_attr($index); ?>"
data-background-url="<?php echo esc_url( $image_url ); ?>"
>
<!-- your content -->
</section>
2. Hook into wp_head or inline style to output CSS for each section
In your theme’s functions.php (or a custom plugin), add something like:
add_action( 'wp_head', 'it_staff_custom_styles' );
function it_staff_custom_styles() {
if ( ! is_singular() ) {
return; // or adjust logic as needed, e.g., only add on pages where needed
}
global $post;
if ( ! $post ) {
return;
}
$repeater_items = get_post_meta( $post->ID, 'it-staff-repeater', true );
if ( empty( $repeater_items ) || ! is_array( $repeater_items ) ) {
return;
}
echo "<style>\n";
foreach ( $repeater_items as $index => $item ) {
// Get image URL
$image = '';
if ( ! empty( $item['it_staff_image'] ) ) {
$img = $item['it_staff_image'];
if ( is_numeric( $img ) ) {
$image = wp_get_attachment_image_url( $img, 'full' );
} elseif ( filter_var( $img, FILTER_VALIDATE_URL ) ) {
$image = $img;
}
}
if ( ! empty( $image ) ) {
// Output CSS using the unique ID pattern
echo "#it_staff_section_{$index} { \n";
echo " background-image: url('". esc_url( $image ) ."');\n";
echo " background-size: cover;\n";
echo " background-position: center center;\n";
echo "}\n";
}
}
echo "</style>\n";
}
Explanation
- This PHP code extracts the repeater data from the post meta.
- Loops over each repeater item.
- Fetches correct image URL (supports both attachment IDs and URLs).
- Prints a CSS block with
background-image targeting unique section IDs.
- Your template must have
<section id="it_staff_section_X"> to tie the CSS to the HTML.
Important:
- The exact way to get repeater data can differ if JetEngine stores it differently. You can also do:
$repeater_items = get_post_meta( $post->ID, 'it-staff-repeater', true );
or if JetEngine has a different way to fetch repeater meta, adapt accordingly.
Bonus: Using JetEngine API to get repeater data
If you want to fetch repeater meta more robustly, you can use JetEngine's API:
$listing_data = jet_engine()->listings->data;
$repeater_items = $listing_data->get( 'it-staff-repeater' );
But this depends on context (whether you're inside a listing template or on single post).
Summary
- Make sure each section has a unique ID (e.g.
id="it_staff_section_0").
- Use PHP in your theme/functions.php to output inline CSS styles setting background-image for each section.
- When rendered, each section will have its own background image pulled from the meta box repeater.
If you want I can help you with the exact snippet tailored based on your Listing Item template or how JetEngine is configured for your case — just share details!