Support

Account

Home Forums General Issues $queried_object breaks search results

Solved

$queried_object breaks search results

  • Hi,

    I’ve created some ACF fields for WooCommerce store categories so the user has the ability to add an image to the top of the returned products per category. See: http://growingleaders.com/product-category/faith-based-resources/ – image is “Habitudes”

    My code for doing this is as follows:

    <?php 			
    // vars
    $queried_object = get_queried_object(); 
    $taxonomy = $queried_object->taxonomy;
    $term_id = $queried_object->term_id;  
    ?>
    
    <?php if( get_field('header_image_cat', $queried_object) ) { ?>
    <h1 class="store-page-title"><img title="<?php woocommerce_page_title(); ?>" alt="<?php woocommerce_page_title(); ?>" class="cat-img" src="<?php the_field('header_image_cat', $queried_object); ?>"></h1>
    <?php } else { ?>
    <h1 class="store-page-title text"><?php woocommerce_page_title(); ?></h1>
    <?php } ?>

    The code works great when having to retrieve and display the values, but when I utilize the search function with WooCommerce, the search results page breaks giving me the error: Catchable fatal error: Object of class stdClass could not be converted to string in /var/www/vhosts/growingleaders.com/httpdocs/wp-content/plugins/advanced-custom-fields-pro/api/api-template.php on line 26 – http://growingleaders.com/?s=habitudes&post_type=product

    When I remove the above code, the search works fine. Any ideas how to get these 2 to work together?

  • Nevermind, I got it resolved. For reference, anywhere I declared $queried_object I replaced with $taxonomy . '_' . $term_id

    For example:

    <?php if( get_field('header_image_cat', $queried_object) ) { ?>

    should read:

    <?php if( get_field('header_image_cat', $taxonomy . '_' . $term_id) ) { ?>

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘$queried_object breaks search results’ is closed to new replies.