I have an Ajax call to a WooCommerce shortcode as follows:
global $wpdb;
// get_the_data
$term_id = $_POST['term_id'];
do_shortcode [products category='$term_id'];
which works OK, but I need to be able to determine which category I am in the loop-start.php, which I have overwritten to display things differently depending on the category.
I have tried numerous ways to get the category within the loop-start.php
global $wpdb;
global $wp_query;
$tableTitle = $wpdb->get_results(
"SELECT slug FROM `wp_terms` WHERE name = '$page_title'"
);
$page_title = $tableTitle[0]->slug;
echo "<h2>page_title is ".$page_title."</h2>";
$cat = $wp_query->get_queried_object();
echo "CAT IS:".print_r($cat,true); // the category needed.
echo "<h2>query_var = ". get_query_var('cat') ."</h2>";
Every way that I have tried returns nothing. How can I get the category or some other indicator of what category this shortcode is being built with?