WordPress.org

Ready to get started?Download WordPress

Forums

Widget Logic
[resolved] Widget on posts within a certain category (6 posts)

  1. Antrock
    Member
    Posted 9 months ago #

    I am trying to use Widget Logic to display a widget only on posts withing a certain category. As far as I am aware is_single() && in_category( 'x' ) should work.

    As I am trying to use this on a WooCommerce page i am using is_single() && in_product_category( 'x' ) but I get an error saying

    Call to undefined function in_product_category() in /home/*/wp-content/plugins/widget-logic/widget_logic.php(284) : eval()'d code on line 1

    .

    I also tried is_product() but it just seems that it won't accept the in_product_category line as I get the same error (is_product_category works fine but I don't need it here). Any ideas how I can fix this? I need this badly as there are many categories of products that need different informations and manuals on the sidebar!

    http://wordpress.org/plugins/widget-logic/

  2. alanft
    Member
    Plugin Author

    Posted 9 months ago #

    you may need to change the 'load logic' point to a later point to ensure the woo_commerce plugin has loaded before the logic is invoked.

    http://wordpress.org/plugins/widget-logic/installation/
    http://wordpress.org/plugins/widget-logic/screenshots/

  3. Antrock
    Member
    Posted 9 months ago #

    I tried every setting there and the same error showed up every time. My default setting is/was 'when all PHP loaded' anyway. Any other idea?

  4. Antrock
    Member
    Posted 9 months ago #

    Still haven't found a solution to this. Why would in_product_category break Widget Logic?

    Logic is_single() && in_product_category( 'x' ) || is_post_type_archive() || is_product_category( 'x' ) breaks Widget Logic on products pages even if they are not in product category X (are in product category Y). Same happens if i use is_product() && in_product_category( 'x' ). If I use in_product_category( 'x' ) it is broken everywhere.

    What could be the cause of this?

  5. alanft
    Member
    Plugin Author

    Posted 9 months ago #

    are you sure there's an in_product_category function? There's is_… but not in_… that I can see here under functions…

    http://docs.woothemes.com/wc-apidocs/

  6. Antrock
    Member
    Posted 9 months ago #

    Alan you were right. I automaticly assumed there must be a function in_product_category (still think there should be one! :-) ). I finally got it to work with is_single && has_term( 'x', 'product_cat' ).

    Thank you for this great plugin!

Reply

You must log in to post.

About this Plugin

About this Topic