Make WordPress Core

Opened 17 years ago

Last modified 5 weeks ago

#5358 assigned defect (bug)

Queried object on multiple tag query holds only first tag

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

Description

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:

print_r($wp_query->get_queried_object());

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 11 years ago.
5358.2.diff (5.8 KB) - added by kovshenin 11 years ago.
5358.3.diff (9.8 KB) - added by kovshenin 11 years ago.

Download all attachments as: .zip

Change History (23)

#1 @ionfish
17 years ago

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

http://comox.textdrive.com/pipermail/wp-hackers/2007-October/015706.html

#2 @Denis-de-Bernardy
15 years ago

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

#3 in reply to: ↑ description @filosofo
15 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
15 years ago

  • Milestone changed from 2.9 to Future Release

#5 @nacin
13 years ago

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

#6 @SergeyBiryukov
13 years ago

  • Keywords needs-patch added; tags wp_query removed

#7 @GaryJ
11 years ago

  • Cc gary@… added

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

#8 @leogermani
11 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.

@wonderboymusic
11 years ago

#9 @wonderboymusic
11 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
11 years ago

  • Keywords needs-refresh added

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

@kovshenin
11 years ago

#11 @kovshenin
11 years ago

  • Keywords needs-refresh removed

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

#12 @wonderboymusic
11 years ago

  • Keywords needs-unit-tests added

@kovshenin - looks good, everything needs unit tests

@kovshenin
11 years ago

#13 @kovshenin
11 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
11 years ago

  • Milestone changed from 3.7 to 3.8

#15 @wonderboymusic
10 years ago

  • Milestone changed from 3.8 to Future Release

#16 @ryan
10 years ago

  • Owner ryan deleted
  • Status changed from new to assigned

#17 @boonebgorges
9 years ago

#31680 was marked as a duplicate.

#18 @GaryJ
8 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
5 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 5 years ago by ivandelajara (previous) (diff)

#20 @Mte90
14 months ago

Looking at this today and many times I had issues for this and needed to create custom URL parameters for filters like for e-commerce (where it can be useful to have multiple categories) it is something that probably today can be very helpful, probably also on REST APIs.

I will try to refresh the patch.

Note: See TracTickets for help on using tickets.