Make WordPress Core

Opened 14 years ago

Last modified 3 years ago

#5358 assigned defect (bug)

Queried object on multiple tag query holds only first tag

Reported by: Kafkaesqui Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version: 2.3.1
Component: Taxonomy Keywords: has-patch
Focuses: Cc:


On tag page results when two or more tags are queried (/tags/foo,bar -or- /tags/foo+bar), only the first tag is in the queried object. So a simple:


outputs a single associative array of the first tag referenced in the query. One would expect to find an array of all tags in the queried object.

Attachments (3)

5358.diff (3.6 KB) - added by wonderboymusic 8 years ago.
5358.2.diff (5.8 KB) - added by kovshenin 8 years ago.
5358.3.diff (9.8 KB) - added by kovshenin 8 years ago.

Download all attachments as: .zip

Change History (22)

#1 @ionfish
14 years ago

Might this question I posted on wp-hackers a while ago be related?

#2 @Denis-de-Bernardy
13 years ago

  • Component changed from General to Taxonomy
  • Owner changed from anonymous to ryan

#3 in reply to: ↑ description @filosofo
13 years ago

Replying to Kafkaesqui:

One would expect to find an array of all tags in the queried object.

Semantically, I would expect something named get_queried_objects(), not get_queried_object(), to return an array of all tags queried: the queried object should be just that---the object queried. If we were to change the behavior of get_queried_object() so that it sometimes returns not an object but an array of objects, we would break all the plugins and themes that expect an object. And we would have to figure out what to do with its complementary method, get_queried_object_id().

A better approach might be to create a new method named get_queried_objects().

#4 @ryan
12 years ago

  • Milestone changed from 2.9 to Future Release

#5 @nacin
11 years ago

I like the idea of get_queried_objects() for non-singular queries.

#6 @SergeyBiryukov
11 years ago

  • Keywords needs-patch added; tags wp_query removed

#7 @GaryJ
9 years ago

  • Cc gary@… added

Probably stating the obvious, but this also applies to categories and other taxonomies - not just tags.

#8 @leogermani
9 years ago

Maybe best solution is let get_queried_objects() deal with everyhting get_queried_object() currently deals with and modify get_queried_object() to call get_queried_objects() and return the first item in the array. That way we wont have duplicated code.

8 years ago

#9 @wonderboymusic
8 years ago

  • Keywords has-patch added; needs-patch removed
  • Milestone changed from Future Release to 3.7

5358.diff introduces get_queried_object_ids, WP_Query::get_queried_object_ids, get_queried_objects, WP_Query::get_queried_objects

#10 @wonderboymusic
8 years ago

  • Keywords needs-refresh added

Patch satisfies the ticket but needs to also support arrays of post_types and authors

8 years ago

#11 @kovshenin
8 years ago

  • Keywords needs-refresh removed

5358.2.diff is a slightly different approach based on @wonderboymusic's work.

#12 @wonderboymusic
8 years ago

  • Keywords needs-unit-tests added

@kovshenin - looks good, everything needs unit tests

8 years ago

#13 @kovshenin
8 years ago

  • Keywords needs-unit-tests removed

Added some unit tests is 5358.3.diff.

One thing I noticed is that although it works well with multiple tags (and covers the issue described in this ticket), it doesn't really work well with multiple post types for example, because when you specify more than one post type is_post_type_archive is no longer true. Then again, what should happen when you query a post type with a tag and an author, especially with get_queried_object_ids()? We might as well just return the whole query_vars array :-P

#14 @wonderboymusic
8 years ago

  • Milestone changed from 3.7 to 3.8

#15 @wonderboymusic
8 years ago

  • Milestone changed from 3.8 to Future Release

#16 @ryan
8 years ago

  • Owner ryan deleted
  • Status changed from new to assigned

#17 @boonebgorges
6 years ago

#31680 was marked as a duplicate.

#18 @GaryJ
6 years ago

Could this be moved forward by solving the original reported problem, and then solve multiple post types in a separate ticket?

#19 @ivandelajara
3 years ago

I found this searching in Google: My solution for this in the today version 5.1.1 has been using get_query_var('tag');

Last edited 3 years ago by ivandelajara (previous) (diff)
Note: See TracTickets for help on using tickets.