Pods Custom Content Types Shortcodes

Below, you’ll find a detailed guide on how to add the Pods – Custom Content Types and Fields Shortcodes to your WordPress website, including their parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Pods – Custom Content Types and Fields Plugin shortcodes not to show or not to work correctly.

Before starting, here is an overview of the Pods – Custom Content Types and Fields Plugin and the shortcodes it provides:

Plugin Icon
Pods – Custom Content Types and Fields

"Pods – Custom Content Types and Fields is a powerful WordPress plugin designed to manage and display custom content types and fields, enhancing your site's functionality."

★★★★☆ (399) Active Installs: 100000+ Tested with: 6.3.2 PHP Version: 7.2
Included Shortcodes:
  • [pods]
  • [pods-form]
  • [pods-content]
  • [pod_sub_template]
  • [pod_once_template]
  • [pod_after_template]
  • [pod_if_field]
  • [acf]

Pods Custom Content Types [pods] Shortcode

The Pods shortcode is a powerful tool that enables the execution of specific functions within your WordPress site. It catches and handles exceptions, providing error messages for easier debugging. This shortcode runs the ‘pods_shortcode_run’ function, which takes in tags and content as parameters. If an exception occurs, it displays an error message, which can be further detailed by enabling WP_DEBUG. The shortcode also includes filters to manage error modes and exception fallbacks, which are removed after execution. This ensures smooth operation and error handling within your WordPress environment.

Shortcode: [pods]

Examples and Usage

Basic example – A simple usage of the Pods shortcode to display the content of a specific Pod template.

[pods name="your_pod_name" template="your_template_name" /]

Advanced examples

Displaying a Pod item by specifying its ID. This will fetch and display the Pod item with the given ID.

[pods name="your_pod_name" id="123" /]

Displaying a Pod item by specifying a field value. This will fetch and display the Pod item where the specified field matches the given value.

[pods name="your_pod_name" where="field_name.value='your_value'" /]

Displaying a list of Pod items with pagination. This will fetch and display a list of Pod items, and include pagination if there are more items than the specified limit.

[pods name="your_pod_name" limit="10" pagination="true" /]

Displaying a list of Pod items and ordering them by a specific field. This will fetch and display a list of Pod items, ordered by the specified field in ascending order.

[pods name="your_pod_name" orderby="field_name ASC" /]

Please replace “your_pod_name”, “your_template_name”, “123”, “field_name”, “your_value” with your actual Pod name, template name, ID, field name, and value respectively.

PHP Function Code

In case you have difficulties debugging what causing issues with [pods] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'pods', 'pods_shortcode' );

Shortcode PHP function:

function pods_shortcode( $tags, $content = null ) {
	pods_doing_shortcode( true );

	$return_exception = static function() {
		return 'exception';
	};

	add_filter( 'pods_error_mode', $return_exception, 50 );
	add_filter( 'pods_error_exception_fallback_enabled', '__return_false', 50 );

	try {
		$return = pods_shortcode_run( $tags, $content );
	} catch ( Exception $exception ) {
		$return = '';

		if ( pods_is_debug_display() ) {
			$return = pods_message(
				sprintf(
					'<strong>%1$s:</strong> %2$s',
					esc_html__( 'Pods Renderer Error', 'pods' ),
					esc_html( $exception->getMessage() )
				),
				'error',
				true
			);

			$return .= '<pre style="overflow:scroll">' . esc_html( $exception->getTraceAsString() ) . '</pre>';
		} elseif (
			is_user_logged_in()
			&& (
				is_admin()
				|| (
					wp_is_json_request()
					&& did_action( 'rest_api_init' )
				)
			)
		) {
			$return = pods_message(
				sprintf(
					'<strong>%1$s:</strong> %2$s',
					esc_html__( 'Pods Renderer Error', 'pods' ),
				esc_html__( 'There was a problem displaying this content, enable WP_DEBUG in wp-config.php to show more details.', 'pods' )
				),
				'error',
				true
			);
		}
	}

	remove_filter( 'pods_error_mode', $return_exception, 50 );
	remove_filter( 'pods_error_exception_fallback_enabled', '__return_false', 50 );

	pods_doing_shortcode( false );

	return $return;
}

Code file location:

pods/pods/classes/PodsInit.php

Pods Custom Content Types and Fields [pods-form] Shortcode

The Pods Plugin shortcode, ‘pods-form’, is designed to display a form on your WordPress site. This shortcode triggers the ‘pods_shortcode_form’ function. The function takes two parameters: tags and content. ‘Tags’ are custom attributes that you can add to the shortcode and ‘content’ is the enclosed content within the shortcode. By setting ‘form’ to 1, the function signals to display a form. This shortcode simplifies the process of adding forms to your site, making it user-friendly even for those with little coding knowledge.

Shortcode: [pods-form]

Parameters

Here is a list of all possible pods-form shortcode parameters and attributes:

  • tags – Array of attributes you want to include in the form
  • content – Content to display within the form, typically null
  • form – A flag indicating the shortcode is creating a form

Examples and Usage

Basic example – A simple shortcode to display a form using the Pods plugin. This shortcode does not include any specific parameters, hence it will display the default form.

[pods-form /]

Advanced examples

Using the shortcode to display a specific form by referencing its ID. The form will load based on the ID provided.

[pods-form id="123" /]

Using the shortcode to display a specific form by referencing its title. The form will load based on the title provided.

[pods-form title="Contact Form" /]

Using the shortcode to display a specific form by referencing both ID and title. The form will first try to load by ID, but if not found, it will try to load by title.

[pods-form id="123" title="Contact Form" /]

Using the shortcode to display a form and also specify a return URL. The user will be redirected to this URL after submitting the form.

[pods-form id="123" thank_you_url="http://example.com/thank-you" /]

Using the shortcode to display a form and also specify a return URL as well as a failure URL. The user will be redirected to the failure URL if there is an error in form submission.

[pods-form id="123" thank_you_url="http://example.com/thank-you" error_url="http://example.com/error" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [pods-form] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'pods-form', 'pods_shortcode_form' );

Shortcode PHP function:

function pods_shortcode_form( $tags, $content = null ) {
	$tags['form'] = 1;

	return pods_shortcode( $tags, $content );
}

Code file location:

pods/pods/classes/PodsInit.php

Pods Custom Content Types [pods-content] Shortcode

The Pods Plugin shortcode is a powerful tool for content management. This shortcode enables you to display specific Pods content on your WordPress site. The given code checks if a Pods page exists. If it doesn’t, it returns a message stating “Pods Page not found”. If the page exists, it returns the content of that specific Pods page.

Shortcode: [pods-content]

Parameters

Here is a list of all possible pods-content shortcode parameters and attributes:

  • page – Specifies the name of the Pods Page to display

Examples and Usage

Basic example – A simple usage of the pods-content shortcode to display a specific Pods Page by its ID

[pods-content page=1 /]

Advanced examples

Displaying a Pods Page by its ID, but with additional parameters. In this case, if the Pods Page with the specified ID is not found, a default message will be displayed instead of the standard “Pods Page not found” message.

[pods-content page=1 notfound="Sorry, the requested page could not be found." /]

Another advanced usage of the pods-content shortcode is to display a Pods Page by its title instead of ID. This can be useful when the ID of the page is not known or if the page is dynamically created and its ID might change.

[pods-content page="About Us" /]

Please note that the ‘page’ parameter in the shortcode can accept either an ID or a title of a Pods Page. The Pods plugin will first try to find a page by ID, and if it can’t, it will try to find a page by title. If it still can’t find a page, it will return the ‘Pods Page not found’ message or a custom message if you’ve specified one using the ‘notfound’ parameter.

PHP Function Code

In case you have difficulties debugging what causing issues with [pods-content] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'pods-content', array( $this, 'shortcode' ) );

Shortcode PHP function:

function shortcode( $tags, $content = null ) {

		if ( ! isset( $tags['page'] ) || empty( $tags['page'] ) ) {
			$tags['page'] = null;
		}

		$pods_page = self::exists( $tags['page'] );

		if ( empty( $pods_page ) ) {
			return '<p>Pods Page not found</p>';
		}

		return self::content( true, $pods_page );
	}

Code file location:

pods/pods/components/Pages.php

Pods Custom Content Types [pod_sub_template] Shortcode

The ‘pod_sub_template’ shortcode, part of the Pods plugin, is used to invoke the ‘frontier_do_subtemplate’ function. This function is typically designed to handle sub-templates in a theme.

Shortcode: [pod_sub_template]

Examples and Usage

Basic example – A simple usage of the ‘pod_sub_template’ shortcode to display a specific template on the front end.

[pod_sub_template id="my_template" /]

Advanced examples

Here, the shortcode is used to display a specific template with additional parameters. The ‘post_type’ parameter is used to specify the type of the post, and the ‘post_status’ parameter is used to specify the status of the post.

[pod_sub_template id="my_template" post_type="post" post_status="publish" /]

In another advanced usage, the shortcode is used to display a specific template with a ‘category’ parameter. This will display posts from a specific category in the specified template.

[pod_sub_template id="my_template" category="news" /]

Note that the ‘id’ parameter in the shortcode is required to specify the template to be displayed, while the other parameters are optional and can be used to filter the posts to be displayed in the template.

PHP Function Code

In case you have difficulties debugging what causing issues with [pod_sub_template] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'pod_sub_template', 'frontier_do_subtemplate' );

Shortcode PHP function:

f

Code file location:

pods/pods/components/Templates/includes/functions-view_template.php

Pods Custom Content Types [pod_once_template] Shortcode

The Pods Plugin shortcode, ‘pod_once_template’, is designed to prevent the duplication of content. It generates a unique hash for each block of content and checks if it has been used before. If the hash exists, the function returns an empty string, avoiding repetition. If not, it adds the hash to the array and processes the template. This ensures each content block is only displayed once.

Shortcode: [pod_once_template]

Parameters

Here is a list of all possible pod_once_template shortcode parameters and attributes:

  • atts – array of attributes passed to the function
  • code – contains the content between the opening and closing of the shortcode
  • id – unique identifier used for the blockhash calculation

Examples and Usage

Basic example – A simple usage of the ‘pod_once_template’ shortcode to display a specific template by its ID.

[pod_once_template id=2 /]

Advanced examples

Using the ‘pod_once_template’ shortcode to display a specific template by referencing the ID and additional attributes. This allows for more control over the output of the shortcode.

[pod_once_template id=2 attribute1=value1 attribute2=value2 /]

Another advanced example could be using the ‘pod_once_template’ shortcode with a nested shortcode inside. This can be useful when you want to include another shortcode within the template output.

[pod_once_template id=2][nested_shortcode][/pod_once_template]

Remember, the ‘pod_once_template’ shortcode allows you to display a specific template only once on a page. If the same template is referenced again in another ‘pod_once_template’ shortcode, it will not be displayed.

PHP Function Code

In case you have difficulties debugging what causing issues with [pod_once_template] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'pod_once_template', 'frontier_template_once_blocks' );

Shortcode PHP function:

function frontier_template_once_blocks( $atts, $code ) {

	global $frontier_once_hashes;

	if ( ! isset( $frontier_once_hashes ) ) {
		$frontier_once_hashes = array();
	}

	$blockhash = md5( $code . $atts['id'] );
	if ( in_array( $blockhash, $frontier_once_hashes, true ) ) {
		return '';
	}
	$frontier_once_hashes[] = $blockhash;

	return pods_do_shortcode( frontier_decode_template( $code, $atts ), frontier_get_shortcodes() );
}

Code file location:

pods/pods/components/Templates/includes/functions-view_template.php

Pods Custom Content Types [pod_after_template] Shortcode

The Pods Plugin shortcode ‘pod_after_template’ is used to add custom content after a specific template. It checks if there’s already content set for the ‘after’ template block. If not, it uses the Pods function ‘pods_do_shortcode’ to process and add the new content.

Shortcode: [pod_after_template]

Parameters

Here is a list of all possible pod_after_template shortcode parameters and attributes:

  • pod – refers to the specific pod type to be used
  • before – block of content to be displayed before the main pod content
  • after – block of content to be displayed after the main pod content

Examples and Usage

Basic example – A simple usage of the ‘pod_after_template’ shortcode, where the ‘pod’ attribute is used to reference a specific pod.

[pod_after_template pod="pod_name" /]

Advanced examples

Using the ‘pod_after_template’ shortcode to reference a specific pod and pass additional parameters to the frontier_template_blocks function. The ‘param1’ and ‘param2’ attributes are used to pass additional parameters to the function.

[pod_after_template pod="pod_name" param1="value1" param2="value2" /]

Using the ‘pod_after_template’ shortcode to reference a specific pod and pass a complex attribute to the frontier_template_blocks function. The ‘complex_param’ attribute is used to pass a complex parameter to the function.

[pod_after_template pod="pod_name" complex_param="value1,value2,value3" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [pod_after_template] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'pod_after_template', 'frontier_template_blocks' );

Shortcode PHP function:

function frontier_template_blocks( $atts, $code, $slug ) {

	global $template_post_blocks;
	if ( ! isset( $template_post_blocks ) ) {
		$template_post_blocks = array(
			'before' => null,
			'after'  => null,
		);
	}
	if ( $slug === 'pod_before_template' ) {
		if ( ! isset( $template_post_blocks['before'][ $atts['pod'] ] ) ) {
			$template_post_blocks['before'][ $atts['pod'] ] = pods_do_shortcode(
				frontier_decode_template( $code, $atts ), array(
					'if',
					'else',
				)
			);
		}
	} elseif ( $slug === 'pod_after_template' ) {
		if ( ! isset( $template_post_blocks['after'][ $atts['pod'] ] ) ) {
			$template_post_blocks['after'][ $atts['pod'] ] = pods_do_shortcode(
				frontier_decode_template( $code, $atts ), array(
					'if',
					'else',
				)
			);
		}
	}

	return null;
}

Code file location:

pods/pods/components/Templates/includes/functions-view_template.php

Pods Custom Content Types [pod_if_field] Shortcode

The Pods Plugin shortcode, ‘pod_if_field’, is a conditional statement used to display content based on the value of a specific field. This shortcode takes various attributes like ‘pod’, ‘id’, ‘field’, ‘value’, ‘compare’, and ‘index’. It fetches the pod object and checks if it exists. If it doesn’t, it returns an empty string. The shortcode also supports calculations for specific fields. It checks if the field is empty and if it has a value to compare with. If it does, it performs various comparisons like equals, not equals, exists, not exists, greater than, less than, etc. If the comparison passes, it uses the IF content as the template. If it doesn’t pass and there’s an ELSE tag, it uses the ELSE content. If there’s no match, it returns an empty string.

Shortcode: [pod_if_field]

Parameters

Here is a list of all possible pod_if_field shortcode parameters and attributes:

  • pod – the name of the Pods custom content type
  • id – unique identifier of the pod item
  • field – the name of the field to check in the pod
  • value – the value to compare with the field’s value
  • compare – the type of comparison to perform
  • index – the index number in a multi-value field

Examples and Usage

Basic example – The shortcode displays the specified pod field if it exists and is not empty.

[pod_if_field pod="example_pod" field="example_field"]Content to display if field exists and is not empty.[/pod_if_field]

Under the hood, the shortcode fetches the specified pod and checks if the field exists. If it does and is not empty, it will display the content enclosed within the shortcode tags.

Advanced examples

Using the shortcode to check if a specific field in a pod matches a given value. If it does, the content within the shortcode tags is displayed.

[pod_if_field pod="example_pod" field="example_field" value="desired_value"]Content to display if field matches the desired value.[/pod_if_field]

In this example, the shortcode fetches the specified pod and checks if the field matches the desired value. If it does, it will display the content enclosed within the shortcode tags.

Using the shortcode to check if a specific field in a pod is greater than or smaller than a given value. If it is, the content within the shortcode tags is displayed.

[pod_if_field pod="example_pod" field="example_field" value="+10"]Content to display if field is greater than 10.[/pod_if_field]

In this example, the shortcode fetches the specified pod and checks if the field is greater than 10. If it is, it will display the content enclosed within the shortcode tags.

PHP Function Code

In case you have difficulties debugging what causing issues with [pod_if_field] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'pod_if_field', 'frontier_if_block' );

Shortcode PHP function:

function frontier_if_block( $attributes, $code ) {
	$attributes = array_merge( [
		'pod'     => null,
		'id'      => null,
		'field'   => null,
		'value'   => null,
		'compare' => null,
		'index'   => null,
	], $attributes );

	$pod = Pods_Templates::get_obj( $attributes['pod'], $attributes['id'] );

	if ( ! $pod || ! $pod->exists() ) {
		return '';
	}

	$code = explode( '[else]', frontier_decode_template( $code, $attributes ) );

	// field data
	$field_data = null;
	$field_type = 'text';

	if ( ! empty( $attributes['field'] ) ) {
		$supported_calculations = [
			'_zebra'          => 'number',
			'_position'       => 'number',
			'_total'          => 'number',
			'_total_found'    => 'number',
			'_total_all_rows' => 'number',
			'_total_pages'    => 'number',
			'_current_page'   => 'number',
		];

		if ( isset( $supported_calculations[ $attributes['field'] ] ) ) {
			// Support [if field="_position" value="2"] and other calculation value handlers.
			$field_data = $pod->field( $attributes['field'] );
			$field_type = $supported_calculations[ $attributes['field'] ];
		} elseif ( '_index' === $attributes['field'] ) {
			$field_data = pods_v( 'index', $attributes );
		} else {
			$field_data = $pod->field( $attributes['field'] );
			$field_type = $pod->fields( $attributes['field'], 'type' );
		}
	}

	$is_empty = true;

	if ( null !== $field_data ) {
		if ( empty( $field_type ) ) {
			$field_type = 'text';
		}

		$is_empty = PodsForm::field_method( $field_type, 'values_are_empty', $field_data );
	}

	$has_value_compare_attribute = null !== $attributes['value'] || null !== $attributes['compare'];

	if ( ! $is_empty || $has_value_compare_attribute ) {
		// Check if we do not have a value to compare with.
		if ( ! $has_value_compare_attribute ) {
			$template = $code[0];

			// Maybe run any shortcode.
			if ( defined( 'PODS_TEMPLATES_ALLOW_OTHER_SHORTCODES' ) && PODS_TEMPLATES_ALLOW_OTHER_SHORTCODES ) {
				$template = frontier_do_other_shortcodes( $template );
			}

			// Field exists and is not empty, use [IF] content
			$template = $pod->do_magic_tags( $template );

			return frontier_do_shortcode( $template );
		}

		$first_character = $attributes['value'] ? substr( (string) $attributes['value'], 0, 1 ) : null;

		// check if + or - are present
		if ( '+' === $first_character ) {
			// is greater
			$attributes['value']   = (float) substr( (string) $attributes['value'], 1 ) + 1;
			$attributes['compare'] = '>';
		} elseif ( '-' === $first_character ) {
			// is smaller
			$attributes['value']   = (float) substr( (string) $attributes['value'], 1 ) - 1;
			$attributes['compare'] = '<';
		}

		if ( empty( $attributes['compare'] ) ) {
			$attributes['compare'] = '=';
		}

		$attributes['compare'] = html_entity_decode( $attributes['compare'] );
		$attributes['compare'] = strtoupper( $attributes['compare'] );

		// Normalize the compare.
		$comparisons = [
			'=',
			'!=',
			'IN',
			'NOT IN',
			'EXISTS',
			'NOT EXISTS',
			'>',
			'>=',
			'<',
			'<=',
			'LIKE',
			'NOT LIKE',
			'EMPTY',
			'NOT EMPTY',
		];

		// Comparison not supported, assume it does not match.
		if ( ! in_array( $attributes['compare'], $comparisons, true ) ) {
			return '';
		}

		$pass = false;

		$maybe_array = is_array( $field_data ) || is_array( $attributes['value'] );

		// Handle comparison.
		if ( '=' === $attributes['compare'] ) {
			if ( $maybe_array ) {
				$pass = in_array( (string) $attributes['value'], (array) $field_data, false );
			} else {
				$pass = (string) $field_data === (string) $attributes['value'];
			}
		} elseif ( '!=' === $attributes['compare'] ) {
			if ( $maybe_array ) {
				$pass = ! in_array( (string) $attributes['value'], (array) $field_data, false );
			} else {
				$pass = (string) $field_data !== (string) $attributes['value'];
			}
		} elseif ( 'EXISTS' === $attributes['compare'] ) {
			$pass = null !== $field_data && [] !== $field_data;
		} elseif ( 'NOT EXISTS' === $attributes['compare'] ) {
			$pass = null === $field_data || [] === $field_data;
		} elseif ( $maybe_array ) {
			// We do not support comparisons for array values beyond equals.
			$pass = false;
		} elseif ( 'IN' === $attributes['compare'] ) {
			$pass = in_array( (string) $field_data, explode( ',', $attributes['value'] ), false );
		} elseif ( 'NOT IN' === $attributes['compare'] ) {
			$pass = ! in_array( (string) $field_data, explode( ',', $attributes['value'] ), false );
		} elseif ( '>' === $attributes['compare'] ) {
			$pass = (float) $field_data > (float) $attributes['value'];
		} elseif ( '>=' === $attributes['compare'] ) {
			$pass = (float) $field_data >= (float) $attributes['value'];
		} elseif ( '<' === $attributes['compare'] ) {
			$pass = (float) $field_data < (float) $attributes['value'];
		} elseif ( '<=' === $attributes['compare'] ) {
			$pass = (float) $field_data <= (float) $attributes['value'];
		} elseif ( 'LIKE' === $attributes['compare'] || 'NOT LIKE' === $attributes['compare'] ) {
			$field_data = (string) $field_data;

			$attributes['value'] = (string) $attributes['value'];

			if ( false !== strpos( $attributes['value'], '%' ) ) {
				// Handle % LIKE values.
				$attributes['value'] = str_replace( '%', '.*', preg_quote( $attributes['value'], '/' ) );

				$found = preg_match( '/^' . $attributes['value'] . '$/Uim', $field_data );

				if ( 0 === $found ) {
					$found = false;
				}
			} else {
				$found = stripos( $field_data, $attributes['value'] );
			}

			if ( 'LIKE' === $attributes['compare'] ) {
				// Check if the string contains the match.
				$pass = false !== $found;
			} elseif ( 'NOT LIKE' === $attributes['compare'] ) {
				// Check if the string does not contain the match.
				$pass = false === $found;
			}
		} elseif ( 'EMPTY' === $attributes['compare'] ) {
			$pass = $is_empty;
		} elseif ( 'NOT EMPTY' === $attributes['compare'] ) {
			$pass = ! $is_empty;
		}

		if ( $pass ) {
			$template = $code[0];

			// Maybe run any shortcode.
			if ( defined( 'PODS_TEMPLATES_ALLOW_OTHER_SHORTCODES' ) && PODS_TEMPLATES_ALLOW_OTHER_SHORTCODES ) {
				$template = frontier_do_other_shortcodes( $template );
			}

			// IF statement true, use [IF] content as template.
			$template = $pod->do_magic_tags( $template );

			return frontier_do_shortcode( $template );
		}

		if ( isset( $code[1] ) ) {
			$template = $code[1];

			// Maybe run any shortcode.
			if ( defined( 'PODS_TEMPLATES_ALLOW_OTHER_SHORTCODES' ) && PODS_TEMPLATES_ALLOW_OTHER_SHORTCODES ) {
				$template = frontier_do_other_shortcodes( $template );
			}

			// There is an [ELSE] tag
			$template = $pod->do_magic_tags( $template );

			return frontier_do_shortcode( $template );
		}

		// Value did not match (and no [ELSE]), nothing should be displayed.
		return '';
	}

	if ( isset( $code[1] ) ) {
		$template = $code[1];

		// Maybe run any shortcode.
		if ( defined( 'PODS_TEMPLATES_ALLOW_OTHER_SHORTCODES' ) && PODS_TEMPLATES_ALLOW_OTHER_SHORTCODES ) {
			$template = frontier_do_other_shortcodes( $template );
		}

		// No value or field is empty and there is an [ELSE] tag. Use [ELSE].
		$template = $pod->do_magic_tags( $template );

		return frontier_do_shortcode( $template );
	}

	// No match at all for the format we support.
	return '';
}

Code file location:

pods/pods/components/Templates/includes/functions-view_template.php

Pods Custom Content Types [acf] Shortcode

The Pods ACF shortcode lets you display custom field data. It uses the Advanced Custom Fields (ACF) plugin to fetch the data. The shortcode takes two parameters: ‘field’ and ‘post_id’. ‘Field’ specifies the custom field to display and ‘post_id’ indicates the post from which to fetch the data. If ‘post_id’ is not provided, it defaults to the current post. Shortcode: [acf field=”your_field” post_id=”your_post_id”]. This shortcode makes it easy to display custom field data anywhere on your site.

Shortcode: [acf]

Parameters

Here is a list of all possible acf shortcode parameters and attributes:

  • post_id – The unique identifier of a specific WordPress post.
  • field – The specific custom field from the Advanced Custom Fields plugin.

Examples and Usage

Basic example – A simple usage of the shortcode to display a specific field from a post using its ID.

[acf field="title" post_id=123 /]

Advanced examples

Using the shortcode to display a specific field from a post without specifying the post ID. In this case, the shortcode will display the field from the current post.

[acf field="content" /]

Using the shortcode to display a specific field from a post by specifying the post ID. In this case, if the post with the specified ID does not exist, the shortcode will not display anything.

[acf field="excerpt" post_id=456 /]

Using the shortcode to display a specific field from a post by specifying the post ID and content. In this case, if the post with the specified ID does not exist, the shortcode will display the content specified.

[acf field="custom_field" post_id=789]Default content[/acf]

PHP Function Code

In case you have difficulties debugging what causing issues with [acf] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'acf', 'pods_acf_shortcode' );

Shortcode PHP function:

function pods_acf_shortcode( $tags, $content ) {

			$post_id = null;

			if ( ! empty( $tags['post_id'] ) ) {
				$post_id = $tags['post_id'];
			}

			$tags = array(
				'field' => $tags['field'],
				'id'    => $post_id,
			);

			return pods_shortcode( $tags, $content );
		}

Code file location:

pods/pods/includes/compatibility/acf.php

Conclusion

Now that you’ve learned how to embed the Pods – Custom Content Types and Fields Plugin shortcodes, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *