Below, you’ll find a detailed guide on how to add the Post Grid Combo – 36+ Gutenberg Blocks 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 Post Grid Combo – 36+ Gutenberg Blocks Plugin shortcodes not to show or not to work correctly.
Before starting, here is an overview of the Post Grid Combo – 36+ Gutenberg Blocks Plugin and the shortcodes it provides:
"Post Grid Combo – 36+ Gutenberg Blocks is a versatile WordPress plugin that enhances your site with 36+ unique Gutenberg blocks, allowing you to create more dynamic and visually appealing posts."
- [post_grid]
- [post_grid_ajax_fetch_block_hub_by_id]
- [eventQuery]
- [post_grid_current_user_id]
- [post_grid_sticky_posts]
- [post_grid_today_date]
Post Grid Combo [post_grid] Shortcode
The Post Grid shortcode is designed to display a grid of posts on your WordPress site. It utilizes the ‘post_grid’ shortcode, which requires an ‘id’ attribute to specify the grid to display. This shortcode calls the ‘post_grid_new_display’ function, which checks if a valid grid id is provided. If not, it displays an error message. If a valid id is given, the function calls the ‘post_grid_main’ action, which handles the display of the grid.
Shortcode: [post_grid]
Parameters
Here is a list of all possible post_grid shortcode parameters and attributes:
id
– Unique identifier for the specific post grid
Examples and Usage
Basic example – Displaying a post grid by referencing the ID.
[post_grid id="123" /]
Advanced examples
Displaying a post grid by referencing the ID, and applying custom attributes via the ‘post_grid_atts’ filter. The grid will load with the custom attributes if defined.
function custom_post_grid_atts( $atts ) {
$atts['custom_attribute'] = 'value';
return $atts;
}
add_filter( 'post_grid_atts', 'custom_post_grid_atts' );
// Then use the shortcode
[post_grid id="123" /]
Using the shortcode to display a post grid by referencing the ID, and triggering a custom action via the ‘post_grid_main’ action. The action will be triggered when the grid is displayed.
function custom_post_grid_main( $atts ) {
// Your custom action here
}
add_action( 'post_grid_main', 'custom_post_grid_main' );
// Then use the shortcode
[post_grid id="123" /]
PHP Function Code
In case you have difficulties debugging what causing issues with [post_grid]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'post_grid', array( $this, 'post_grid_new_display' ) );
Shortcode PHP function:
function post_grid_new_display($atts, $content = null ){
$atts = shortcode_atts(
array(
'id' => "",
),
$atts
);
$atts = apply_filters('post_grid_atts', $atts);
$grid_id = $atts['id'];
ob_start();
if(empty($grid_id)){
echo 'Please provide valid post grid id, ex: <code>[post_grid id="123"]</code>';
return;
}
//include( post_grid_plugin_dir . 'templates/post-grid.php');
do_action('post_grid_main', $atts);
return ob_get_clean();
}
Code file location:
post-grid/post-grid/includes/classes/class-shortcodes.php
Post Grid Combo – 36+ Gutenberg Blocks [eventQuery] Shortcode
The ‘eventQuery’ shortcode is designed to query and display posts from a specific date. It uses the ‘event_date’ meta key to filter posts before a set date. In detail, the shortcode initiates a new WP_Query with ‘post’ as post_type and a meta_query for ‘event_date’. It then loops through the posts, capturing the title of each and echoing it out.
Shortcode: [eventQuery]
Examples and Usage
Basic example – A fundamental usage of the ‘eventQuery’ shortcode is to call it without any parameters. This will display a list of post titles that have an event date earlier than June 23, 2022.
[eventQuery /]
PHP Function Code
In case you have difficulties debugging what causing issues with [eventQuery]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode('eventQuery', 'eventQuery');
Shortcode PHP function:
function eventQuery()
{
$meta_query = array(
'relation' => 'OR',
array(
'key' => 'event_date',
'value' => 20220623,
'compare' => '<',
'type' => 'DATE',
)
);
$args = array(
'post_type' => 'post',
'meta_query' => $meta_query,
);
$query = new WP_Query($args);
$html = ob_start();
while ($query->have_posts()) : $query->the_post();
$post_id = get_the_ID();
$title = get_the_title($post_id);
echo $title;
echo '<br/>';
endwhile;
return ob_get_clean();
}
Code file location:
post-grid/post-grid/includes/functions.php
Post Grid Combo – 36+ Gutenberg Blocks [post_grid_current_user_id] Shortcode
The Post Grid Current User ID shortcode is a powerful tool in WordPress. It retrieves and displays the ID of the currently logged-in user. The PHP function get_current_user_id() is called within this shortcode, enabling it to fetch the user’s ID. This is particularly useful for personalizing content or tracking user activity.
Shortcode: [post_grid_current_user_id]
Examples and Usage
Basic example – This shortcode allows you to retrieve the ID of the current user.
[post_grid_current_user_id]
PHP Function Code
In case you have difficulties debugging what causing issues with [post_grid_current_user_id]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode('post_grid_current_user_id','post_grid_current_user_id');
Shortcode PHP function:
function post_grid_current_user_id(){
return get_current_user_id();
}
Code file location:
post-grid/post-grid/includes/shortcodes/shortcode-current_user_id.php
Post Grid Combo [post_grid_sticky_posts] Shortcode
The ‘post_grid_sticky_posts’ shortcode is a function in PHP that retrieves and returns a list of sticky posts in WordPress. This shortcode is designed to fetch the IDs of the sticky posts set in your WordPress site. These IDs are then returned as a string, separated by commas.
Shortcode: [post_grid_sticky_posts]
Examples and Usage
Basic example – The basic usage of the shortcode is to display the sticky posts in your WordPress website. This shortcode will return the IDs of the sticky posts, separated by commas.
[post_grid_sticky_posts]
Advanced examples
Since the given shortcode does not accept any parameters, we can’t provide an advanced example with more parameters. However, we can modify the function to accept parameters and provide a more advanced usage example.
Let’s modify the function to accept a parameter ‘separator’ that will be used to separate the post IDs.
function post_grid_sticky_posts($atts){
$atts = shortcode_atts( array(
'separator' => ','
), $atts, 'post_grid_sticky_posts' );
$sticky_posts = get_option( 'sticky_posts' );
$sticky_posts = implode($atts['separator'],$sticky_posts);
return $sticky_posts;
}
add_shortcode('post_grid_sticky_posts','post_grid_sticky_posts');
Now, you can use the shortcode with the ‘separator’ parameter. For example, if you want to separate the post IDs with a semicolon instead of a comma, you can use the following shortcode:
[post_grid_sticky_posts separator=";"]
PHP Function Code
In case you have difficulties debugging what causing issues with [post_grid_sticky_posts]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode('post_grid_sticky_posts','post_grid_sticky_posts');
Shortcode PHP function:
function post_grid_sticky_posts(){
$sticky_posts = get_option( 'sticky_posts' );
$sticky_posts = implode(',',$sticky_posts);
return $sticky_posts;
}
Code file location:
post-grid/post-grid/includes/shortcodes/shortcode-sticky-posts.php
Post Grid Combo [post_grid_today_date] Shortcode
The ‘post_grid_today_date’ shortcode is a PHP function that returns the current date. It utilizes the PHP ‘date’ function to get the date in “Y-m-d” format. The ‘format’ attribute allows for customization of the date format. By default, it’s set to “Y-m-d”, but can be changed according to PHP date formats.
Shortcode: [post_grid_today_date]
Parameters
Here is a list of all possible post_grid_today_date shortcode parameters and attributes:
format
– Defines the date format to be displayed
Examples and Usage
Basic example – The following example demonstrates the basic usage of the ‘post_grid_today_date’ shortcode. This shortcode will return the current date in the format “Y-m-d”.
[post_grid_today_date]
Advanced examples
1. Displaying the date in a different format – You can customize the format of the date by passing the ‘format’ attribute. For instance, if you want the date to be displayed in the “d-m-Y” format, you can use the following shortcode:
[post_grid_today_date format="d-m-Y"]
2. Displaying the date and time – If you want to display the current date and time, you can use the ‘format’ attribute to specify a format that includes time. Here’s an example where the date and time are displayed in the “Y-m-d H:i:s” format:
[post_grid_today_date format="Y-m-d H:i:s"]
PHP Function Code
In case you have difficulties debugging what causing issues with [post_grid_today_date]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode('post_grid_today_date', 'post_grid_today_date');
Shortcode PHP function:
function post_grid_today_date($atts, $content = null)
{
$atts = shortcode_atts(
array(
'format' => "Y-m-d",
),
$atts
);
$format = $atts['format'];
return date($format);
}
Code file location:
post-grid/post-grid/includes/shortcodes/shortcode-today-date.php
Conclusion
Now that you’ve learned how to embed the Post Grid Combo – 36+ Gutenberg Blocks 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.
Leave a Reply