[Support request] Element conditions on multiple post types archive – array to string conversion

Home Forums Support [Support request] Element conditions on multiple post types archive – array to string conversion

Home Forums Support Element conditions on multiple post types archive – array to string conversion

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1520380
    Fabian

    Hi,
    I’m getting an Array to string conversion in /var/www/html/wp-content/plugins/gp-premium/elements/class-conditions.php on line 216 error.

    I’m using a block element with a condition set to be on “Product Archives” (WooCommerce product post type).
    I’m also setting the post_type query var of the main query to an array of ['product', 'product_variation']. Now in gp-premium/elements/class-conditions.php on line 216 it get’s the query var and appends it to a string ($location). That doesn’t work if the query var is an array. It’s valid for the post_type query var to be an array (see https://developer.wordpress.org/reference/classes/wp_query/#post-type-parameters)

    I think it could be fixed by checking if it’s an array, but I can’t give an advice what to do if it’s an array – probably imploding the array with a glue (,) won’t work with other matching techniques in the conditions class?
    Like so:
    `
    $postType = $wp_query->get( ‘post_type’ );
    if(is_array($postType)){
    $location = ‘archive:’ . $postType[0];
    } else {
    $location = ‘archive:’ . $postType;
    }
    `

    I’m doing all this to include product_variations as well in the loop – via a plugin (yith) but also via custom code.
    In my special case it would be enough to just take the first item of the post_type array, but don’t know if that works for other cases.

    GP Premium Version: 1.12.2

    #1520812
    Leo
    Staff
    Customer Support

    Hi there,

    Sorry not sure if I fully understand.

    Is this for a custom function you are using?

    Doesn’t sound like it’s related to GP.

    Let me know πŸ™‚

    #1523385
    Fabian

    Sorry I was being unclear, I updated the OP to include more detailed information πŸ‘

    #1524501
    Tom
    Lead Developer
    Lead Developer

    Interesting, thanks for this! Can you expand on what you’re doing to have that query return as an array so I can replicate and find a solid solution?

    Appreciate it!

    #1526925
    Fabian

    Thanks for your reply – of course: In my case it’s for showing product_variations in the archives as well (eg a product with four variations shows as four single products). That’s done via YITH WooCommerce Color and Label Variations (https://yithemes.com/themes/plugins/yith-woocommerce-color-and-label-variations/) but it’s not a problem of the plugin, because manually setting the query var to an array (in any other case) brings the same problem.
    I want to show some GP elements (infos about current discounts) on all product archives, therefore i’m using the “product archive” condition.
    So in this case the archive is_post_type_archive returns true but it’s not only the archive of one post type.
    Is there any way I could circumvent this with other conditions? It should also show on the shop page so only choosing “product category archives” and “product taxonomy archives” is not enough.
    I also don’t see any way to circumvent this via a custom hook or via code, because the GeneratePress_Conditions::get_current_location always runs.

    #1527476
    Tom
    Lead Developer
    Lead Developer

    Perfect – thanks! Will look into this for 1.13.0 πŸ™‚

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.