I am creating my very own plugin for my wordpress. I create a shortcode for my plugin and CPT with a customized taxonomy and customized single-CPT.
When I attempt to use the perform get_template_part() in my shortcode, the result’s a name to a single.php template from the theme. How I can restrict the place get_template_part can search for recordsdata?
That is my shortcode:
perform shortcode_display_products ( $atts ){
international $wpdb;
$question = '';
$atts = shortcode_atts( array(
'classes' => ''
), $atts, 'shortcode_display_products');
if( !empty($atts['categories']) && !is_null($atts['categories']) ){
$question = new WP_Query( array(
'post_type' => 'merchandise',
'post_status' => 'public',
'tax_query' => array(
array(
'taxonomy'=> 'teams',
'discipline' => 'slug',
'phrases' => '"'.$atts['categories'].'"'
)
),
'showposts' => -1,
'orderby' => 'date',
'order' => 'DESC'
));
}
else{
$question = new WP_Query( array(
'post_type' => 'merchandise',
'post_status' => 'public',
'showposts' => -1,
'orderby' => 'date',
'order' => 'DESC'
));
}
ob_start();
if( $query->have_posts() ){
$c = 0;
whereas ( $question -> have_posts() ){
$question -> the_post();
get_template_part('single','merchandise');
$c++;
}
}
else{
return esc_html__('Not discovered any product register',P_TEXTDOMAIN);
}
wp_reset_postdata();
return ob_get_clean();
}
add_shortcode('display_products','shortcode_display_products');
That is my single-products:
if ( !is_single() ){
embody '/type/products-form.php';
$idnumber = ( is_single() )? '': '-'.$c;
?>
<div class="card">
<div class="card-header" id="heading<?= $idnumber?>">
<h5 class="mb-0">
<button class="btn btn-link" data-toggle="collapse" data-target="#collapse<?= $idnumber?>" aria-expanded="true" aria-controls="collapse<?= $idnumber?>">
<?= $post->title ?>
</button>
</h5>
</div>
<div id="collapse<?= $idnumber?>" class="collapse present" aria-labelledby="heading<?= $idnumber?>" data-parent="#accordion">
<div class="card-body">
<?= $post->content material ?>
<?php create_product_form() ?>
</div>
</div>
</div>
<?php }
else{ _e('nothing else',P_TEXTDOMAIN);}
}