su_shortcode_post

The shortcodes-ultimate su shortcode post function.

Published Date - February 15, 2021

Description

su_shortcode_post( $atts, $content );

Parameters

  1. $atts

  2. $content


Usage

The following example is for adding a hook callback.

if ( !function_exists( 'su_shortcode_post' ) ) {
    require_once ABSPATH . PLUGINDIR . 'shortcodes-ultimateshortcodes-ultimate/includes/shortcodes/post.php';
}

// The input(s). 
$atts = null;
$content = null;

// NOTICE! Understand what this does before running.
$result = su_shortcode_post( $atts, $content );
            

Defined

The function is defined in the following location(s).

shortcodes-ultimate/includes/shortcodes/post.php

function su_shortcode_post( $atts = null, $content = null ) {

	$atts = su_parse_shortcode_atts(
		'post',
		$atts,
		array( 'filter_content' => 'no' )
	);

	if ( ! $atts['post_id'] ) {
		$atts['post_id'] = get_the_ID();
	}

	if ( ! $atts['post_id'] ) {

		return su_error_message(
			'Post',
			__( 'invalid post ID', 'shortcodes-ultimate' )
		);

	}

	if ( 'the_content' === $atts['field'] ) {

		$atts['field']          = 'post_content';
		$atts['filter_content'] = 'yes';

	}

	$data = '';
	$post = su_is_positive_number( $atts['post_id'] )
		? get_post( $atts['post_id'] )
		: get_page_by_path( $atts['post_id'], OBJECT, $atts['post_type'] );

	if ( isset( $post->{$atts['field']} ) ) {
		$data = $post->{$atts['field']};
	}

	if ( 'yes' === $atts['filter_content'] ) {
		$data = su_filter_the_content( $data );
	}

	if (
		$atts['filter'] &&
		su_is_filter_safe( $atts['filter'] ) &&
		function_exists( $atts['filter'] )
	) {
		$data = call_user_func( $atts['filter'], $data );
	}

	if ( empty( $data ) ) {
		$data = $atts['default'];
	}

	return $data ? $atts['before'] . $data . $atts['after'] : '';

}