AI Verified

Name

WordPress Repeater Custom Field Show

About

After enabling Custom Fields you can show Repeater Fields on your site via a Shortcode.

Language

PHP

Rating

Voted: 0 by 0 user(s)

How to Setup Snippet

/*Use this Code to return Repeater Custom Fields with Comma*/ function display_location_fields() { $post_id = get_the_ID(); // Get current post ID $locations = get_post_meta($post_id, 'Location', false); // Retrieve all values for 'Location' field if (!empty($locations)) { return implode(', ', $locations); // Return locations separated by commas } return ''; // Return empty string if no locations } add_shortcode('display_locations', 'display_location_fields'); /* Use this Code to return Repeater Custom Fields as List function display_location_fields() { $post_id = get_the_ID(); // Get current post ID $locations = get_post_meta($post_id, 'Location', false); // Retrieve all values for 'Location' field if (!empty($locations)) { $list_html = '<ul>'; foreach ($locations as $location) { $list_html .= '<li>' . esc_html($location) . '</li>'; // Create a list item for each location } $list_html .= '</ul>'; return $list_html; } return ''; // Return empty string if no locations } add_shortcode('display_locations', 'display_location_fields'); */

Codevault

WebSquadron

Scroll down to see more snippets from this codevault.

Wordpress Compatability

The author has indicated that this snippet is compatable up to wordpress version: 6.1

Our AI bot has checked this snippet is compatable up to wordpress version: 6.1

Code Snippet Plugin Sync

Free & Pro

Download this snippet by clicking the download button, then head over to the Code Snippet Plugin settings in your wordpress admin dashboard, select the import menu then upload this file to import into your wordpress site.

Pro Only (Coming Soon)

You will be able to click a button and sync this snippet to your wordpress site automatically and from your dashboard manage all code snippets across all your wordpress sites that have the Code Snippets Pro plugin installed.

History

Last modified:

11/12/2023

Important Note

This snippet has the following status:

AI Verified

This snippet has been tested by our AI bot, see any comments below.

AI Bot Comments:

Found 0 vulnerabilities

WordPress Repeater Custom Field Show

 
                    
1/*Use this Code to return Repeater Custom Fields with Comma*/
2function display_location_fields() {
3 $post_id = get_the_ID(); // Get current post ID
4 $locations = get_post_meta($post_id, 'Location', false); // Retrieve all values for 'Location' field
5 
6 if (!empty($locations)) {
7 return implode(', ', $locations); // Return locations separated by commas
8 }
9 
10 return ''; // Return empty string if no locations
11}
12add_shortcode('display_locations', 'display_location_fields');
13 
14 
15/* Use this Code to return Repeater Custom Fields as List
16function display_location_fields() {
17 $post_id = get_the_ID(); // Get current post ID
18 $locations = get_post_meta($post_id, 'Location', false); // Retrieve all values for 'Location' field
19 
20 if (!empty($locations)) {
21 $list_html = '<ul>';
22 foreach ($locations as $location) {
23 $list_html .= '<li>' . esc_html($location) . '</li>'; // Create a list item for each location
24 }
25 $list_html .= '</ul>';
26 return $list_html;
27 }
28 
29 return ''; // Return empty string if no locations
30}
31add_shortcode('display_locations', 'display_location_fields');
32*/

0

Related Snippets

Please see some snippets below related to this snippet..

General

AI Verified

0

Featured image open graph meta tag

Added: 1 year ago

Last Updated: 1 year ago

Adds an open graph tag to your site for posts that have a featured image, allowing it to show up in RSS feeds and on social media sites.

General

AI Verified

0

Disable Admin Bar for All Users Except Admins

Added: 8 months ago

Last Updated: 2 weeks ago

General

AI Verified

0

Stop P tags

Added: 1 year ago

Last Updated: 1 year ago

Prevent wordpress from automatically adding p tags around everything

Other Snippets in this Codevault

These are some popular snippets from this users codevault..

Performance

AI Verified

32

Remove Unused Javascript

Added: 1 year ago

Last Updated: 3 days ago

Remove Unused Javascript - and improve your Page Speed Insight Score

WooCommerce

Pro Verified

10

Deactivate some WooCommerce Checkout Fields

Added: 1 year ago

Last Updated: 2 weeks ago

Deactivate some WooCommerce Checkout Fields from showing

Elementor

AI Verified

6

CSS Grid Aid

Added: 8 months ago

Last Updated: 1 month ago

This can be used for any WordPress Builder to aid working with CSS Grids.