Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed behaviour of get_queried_object #264

Closed
RobMaple opened this issue Jul 9, 2024 · 7 comments
Closed

Changed behaviour of get_queried_object #264

RobMaple opened this issue Jul 9, 2024 · 7 comments

Comments

@RobMaple
Copy link

RobMaple commented Jul 9, 2024

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
Copy link
Owner

Log1x commented Jul 9, 2024

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
Copy link
Author

RobMaple commented Jul 9, 2024

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

@Log1x
Copy link
Owner

Log1x commented Jul 9, 2024

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 #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
Copy link
Author

RobMaple commented Jul 9, 2024

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
Copy link
Owner

Log1x commented Jul 9, 2024

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
Copy link
Author

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
Copy link
Owner

Log1x commented Jul 10, 2024

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.

@Log1x Log1x closed this as completed Jul 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants