custom post types – Problem with shortcode
Question
please tell me whats wrong? I have post type + custom taxonomy, i need display via shortcode with my posts in post type via category params:
function list_faqs_shortcode( $atts ) {
// Parse your shortcode settings with it's defaults
$atts = shortcode_atts( array(
'category' => ''
), $atts, 'myprefix_custom_grid' );
// Extract shortcode atributes
extract( $atts );
$categories = explode(',', $atts['category']);
// Define output var
$output="";
// Define query
$query_args = array(
'post_type' => 'cstore_faq', // Change this to the type of post you want to show
'posts_per_page' => $posts_per_page,
);
// Query by term if defined
if ( $term ) {
$query_args['tax_query'] = array(
array(
'taxonomy' => 'category_list',
'field' => 'term_id',
'terms' => $categories,
//'terms' => $term,
),
);
}
echo $categories;
// Query posts
$custom_query = new WP_Query( $query_args );
// Add content if we found posts via our query
if ( $custom_query->have_posts() ) {
// Open div wrapper around loop
$output .= '<div>';
// Loop through posts
while ( $custom_query->have_posts() ) {
// Sets up post data so you can use functions like get_the_title(), get_permalink(), etc
$custom_query->the_post();
// This is the output for your entry so what you want to do for each post.
$output .= '<div>!!' . get_the_title() . '!!</div>';
}
// Close div wrapper around loop
$output .= '</div>';
// Restore data
wp_reset_postdata();
}
// Return your shortcode output
return $output;
}
add_shortcode( 'faq_list', 'list_faqs_shortcode' );
and my shortcode:
[faq_list category=”77″]
but not displayed nothing, if i try display like [faq_list] my posts all displayed correctly, whats wrong? thank you.
0
2 months
2022-12-11T18:44:50-05:00
2022-12-11T18:44:50-05:00 0 Answers
0 views
0
Leave an answer