I'm trying to make a shortcode with two parameters $number_posts
and $category_name
.
The shortcode is calling another function named bg_make_post_grid
that uses those parameters as variables.
I added wp_die()
to the function to see if it was being called, and it does not kill WordPress so I don't think the function is being called.
What am I doing wrong?
// Add Shortcode
add_shortcode( 'bg_recent_post_grid', 'bg_recent_post_grid_shortcode' );
function bg_recent_post_grid_shortcode( $atts ) {
// Attributes
$atts = shortcode_atts(
array(
'category_name' => 'uncategorized',
'number_posts' => '1',
), $atts );
return bg_make_post_grid ( $atts['number_posts'], $atts['category_name'] );
}
function bg_make_post_grid ( $number_posts, $category_name ) {
$args = array(
'numberposts' => $number_posts,
'category' => $category_name,
'orderby' => 'post_date',
'order' => 'DESC',
'post_type' => 'post',
);
$recent_posts = wp_get_recent_posts( $args );
wp_die();
}
bg_make_post_grid()
return a value or echo something?echo do_shortcode('[bg_recent_post_grid]');
orecho bg_recent_post_grid_shortcode([]);
? And where did you add the code? Is it infunctions.php
or a plugin you wrote?