Log1x / acf-composer

Compose ACF Fields, Blocks, Widgets, and Option Pages with ACF Builder on Sage 10.
https://github.com/Log1x/acf-composer
MIT License
413 stars 56 forks source link

Changed behaviour of get_queried_object #264

Closed RobMaple closed 1 month ago

RobMaple commented 1 month ago

Sorry if this is a bit vague but I've run into an issue after upgrading from version 2 to 3 that seems to effect the behaviour of get_queried_object.

I have a taxonomy archive page that also allows filtering posts by a secondary taxonomy and term - the URL structure looks like: https://example.com/taxonmy_a/term?taxonomy_b=term

Using version 2 of acf-composer, get_queried_object returns the term of taxonomy_a as I would expect whereas when using version 3, get_queried_object now returns the term of taxonomy_b.

I'm not quite sure why thats happening but for now I've rolled back to v2 -- is there something I've not considered about the updated functionality?

Log1x commented 1 month ago

you can try tweaking the priority on https://github.com/Log1x/acf-composer/blob/master/src/AcfComposer.php#L101 – is it a custom taxonomy?

RobMaple commented 1 month ago

Thanks for the suggestion, no luck with tweaking the priority though. Yes both taxonomies are custom.

Log1x commented 1 month ago

You're going to have to give more info then. How are they custom? How are you registering them? What hooks are they in? Even if you change from acf/init to init on that hook, it has the same affect? Are you sure your post types/taxonomies are being registered in a proper hook?

You can also surf the code diff at https://github.com/Log1x/acf-composer/pull/193 but a good bit more has changed since then.

I also don't 100% understand your issue without seeing code. What do you mean by changing the output of get_queried_object() – like the entire object is different? Completely unrelated to ACF? ACF Composer doesn't do anything that would ever affect a query.

RobMaple commented 1 month ago

Yeah sure. So one taxonomy, the 'route' one in the URL structure mentioned, is actually a woocommerce tax 'product_cat' ( sorry mistakenly thought it was custom for some reason ). The other taxonomy is custom and registered using poet (2.1.0) - this is also registered against the woocommerce 'product' post type.

This is the poet config for that tax:

'collection' =>
            [
                'links' => 'product',
                'label' => __('Collections'),
                'rewrite' => ['slug' => 'collection', 'with_front' => false],
                'hierarchical' => true,
                'show_in_rest' => true,
                'meta_box_cb' => 'post_categories_meta_box',
                'show_ui' => true,
                'show_in_nav_menus' => true,
            ],

In terms of the get_queried_object call, that happens in a sage view component class that is used to filter products by both taxonomy terms in some specific instances.

Not sure if that helps -- happy to share more ocde if necessary. I've tried changing acf/init to init but no luck with that either. Will take a look through the diff tomorrow for any more clues.

Log1x commented 1 month ago

I'm not really sure, especially without seeing any of the object code.

Perhaps try tweaking this change from Poet?

I find this all a little strange as the combined changes with the latest Poet and ACF Composer v3 increased compatibility for me quite a bit, especially when trying to dynamically create fields inside of field groups/blocks – but I also do everything in my power to avoid WooCommerce. 😆

RobMaple commented 1 month ago

Had a chance to take another look this morning and turns out switching the poet hookPriority to 5 fixes the issue. I'd mistakely assumed it was the major version bump of acf-composer that was the issue but actually the minor version change of poet that was causing the issue.

Log1x commented 1 month ago

If you add 'hookPriority' => 5 into your poet.php config it should fix your issue. If I get more reports of this I'll explore other options – but this seems to be a weird quirk with WooCommerce and will otherwise cause issues with having post types/taxonomies registered in time to be able to query them while dynamically creating field types.