Content Views Query And Display Post Page Shortcode

Below, you’ll find a detailed guide on how to add the Content Views Query And Display Post Page Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Content Views Query And Display Post Page Plugin shortcode not to show or not to work correctly.

Before starting, here is an overview of the Content Views Query And Display Post Page Plugin and the shortcodes it provides:

Plugin Icon
Content Views – Post Grid Gutenberg Blocks and Shortcode

"Content Views – Post Grid Gutenberg Blocks and Shortcode is a versatile plugin that allows users to easily query and showcase post/page content in a visually appealing grid layout using Gutenberg blocks and shortcodes."

★★★★☆ (325) Active Installs: 100000+ Tested with: 6.3.2 PHP Version: 5.5
Included Shortcodes:
  • [PT_CV_POST_TYPE]

Content Views Query And Display Post Page [PT_CV_POST_TYPE] Shortcode

The Content Views Query and Display Post Page plugin shortcode is a powerful tool that generates and displays customized post views. This shortcode uses the ‘view_output’ function to process and display the settings of a specific view. It first backs up the global post, then applies filters to the shortcode output. If the result is empty, it retrieves the view settings, processes them, and generates the final output. Afterward, it restores the global post to its original state.

Shortcode: [PT_CV_POST_TYPE]

Parameters

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

  • id – Unique identifier of the view to be displayed

Examples and Usage

Basic example – The shortcode below displays a post view by referencing the ID. This is a basic usage of the shortcode that allows you to display a specific post view on your page.

[PT_CV_POST_TYPE id=1 /]

PHP Function Code

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

Shortcode line:

add_shortcode( PT_CV_POST_TYPE, array( 'PT_CV_Functions', 'view_output' ) );

Shortcode PHP function:

function view_output( $atts ) {
			$atts	 = shortcode_atts( apply_filters( PT_CV_PREFIX_ . 'shortcode_params', array( 'id' => 0 ) ), $atts );
			$id		 = cv_sanitize_vid( $atts[ 'id' ] );
			if ( $id && !self::duplicated_process( $id, $atts ) ) {
				# Backup the global post
				if ( isset( $GLOBALS[ 'post' ] ) ) {
					$GLOBALS[ 'cv_gpost_bak' ] = $GLOBALS[ 'post' ];
				}

				$result = apply_filters( PT_CV_PREFIX_ . 'view_shortcode_output', null, $atts );
				if ( empty( $result ) ) {
					$settings	 = PT_CV_Functions::view_get_settings( $id );
					$view_html	 = PT_CV_Functions::view_process_settings( $id, $settings, null, $atts );
					$result		 = PT_CV_Functions::view_final_output( $view_html );
					do_action( PT_CV_PREFIX_ . 'flushed_output', $result );
				}

				# Restore the global post
				if ( isset( $GLOBALS[ 'cv_gpost_bak' ] ) ) {
					$GLOBALS[ 'post' ] = $GLOBALS[ 'cv_gpost_bak' ];
					unset( $GLOBALS[ 'cv_gpost_bak' ] );
				}

				return $result;
			}
		}

Code file location:

content-views-query-and-display-post-page/content-views-query-and-display-post-page/public/content-views.php

Conclusion

Now that you’ve learned how to embed the Content Views Query And Display Post Page Plugin shortcode, 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 *