Skip to content
This repository has been archived by the owner on May 10, 2022. It is now read-only.

extend review query for any custom taxonomy and post type #263

Open
selul opened this issue Mar 21, 2018 · 14 comments
Open

extend review query for any custom taxonomy and post type #263

selul opened this issue Mar 21, 2018 · 14 comments
Assignees

Comments

@selul
Copy link
Contributor

selul commented Mar 21, 2018

@contactashish13 I know that you might not like this but it seems a lot of users requested filtering reviews by custom taxonomies and tags.

In order to do this, we need to extend the wp_query to allow using custom taxonmies, not only categories as it does not.

Let me know if you have any suggestion on how we can do this.

@contactashish13
Copy link
Contributor

@selul This already supported custom post types. I've added support for tags and custom taxonomy. Now either tags or category or tag AND category can be queried. PR: #268

But the problem with related reviews still remains because that query has a tag OR category which I can't seem to fit here.

@selul
Copy link
Contributor Author

selul commented Apr 2, 2018

@contactashish13 i see this extended for tags, not all custom taxonomies. also why we don't use in the model two params, taxonomy_name and terms_ids which will filter the reviews based on those?
I'm talking something like:

$post = array(
			'category_id'           => false,
			'category_name'         => false,
			'post_type'             => array( 'post', 'page' ),
			'post_date_range_weeks' => false,
			'taxonomy_name'                  => 'category',
			'term_ids'     => array(), 
		)

which will be generally used regardless of any taxonomy the user is choosing ( category, tag, etc )

Also, for backwards compatibility, we can populate the terms_ids based on category_ids or category_name, if provided, for keeping backwards compatibility.

@contactashish13
Copy link
Contributor

contactashish13 commented Apr 3, 2018

@selul taxonomy_category and taxonomy_tag allow for any custom taxonomy

`
$post = array(

		'category_id'           => false,

		'category_name'         => false,

		'post_type'             => array( 'post', 'page' ),

		'post_date_range_weeks' => false,

		'tags'                  => false,

		'taxonomy_category'     => 'category',

		'taxonomy_tag'          => 'post_tag',

	),

`

and the reason I have had to add two is to support tags and categories, not tags or categories

@selul
Copy link
Contributor Author

selul commented Apr 3, 2018

@contactashish13 I understand now.

Can we collapse this into a single taxonomy usage, we don't need filtering by multiple taxonomy at the same time, it will be either tags or category or anything else.

I will suggest that we can simplify the input into something like this:

$post = array(
			'category_id'           => false,
			'category_name'         => false,
			'post_type'             => array( 'post', 'page' ),
			'post_date_range_weeks' => false,
			'term_ids'                  => array(),
			'taxonomy'     => 'category', 
)

Where term_ids will be either array of slugs or term_ids and the taxonomy is the taxonomy slug which we will be used for filtering, i.e tags, category, download_tag, etc.

Following this example, we will reduce the query from get_sub_query_posts into a single one, based on the taxonomy selection, as well as we can remove the category_name and category_id filtering in get_sub_query_conditions and target only the term_ids array.

In order to have backwards compatibility, we will detect before building the query, if we have values for category_id or category_name and prepopulate the term_ids in this case.

In order to know if to detect if the get_sub_query_conditions will filter by term_id or term_slug, you can get the first value from term_ids input, and if that value is numeric, restrict to term_id, if not to term_slug.

Let me know what do you think about this approach.

@contactashish13
Copy link
Contributor

@selul i added support for both tags and categories because related reviews widget does that. The only difference is it uses tags OR categories. Do you want to still simplify the query?

@selul
Copy link
Contributor Author

selul commented Apr 3, 2018

yep, the logic inside related widgets can be simplified also to reduce only to fetch reviews only for similar tags.

What do you think ?

@contactashish13
Copy link
Contributor

@selul the current widget works on categories or tags so existing customers who don't tag reviews and tend to group reviews into categories might suffer.

@selul
Copy link
Contributor Author

selul commented Apr 3, 2018

that's fine for now.

@contactashish13
Copy link
Contributor

@selul or we can add an option to the widget where the user can select if they want similarity on the basis of tags or categories. And we can default this to categories. Do you think that would work?

@selul
Copy link
Contributor Author

selul commented Apr 3, 2018

yep, much better this way.

@contactashish13
Copy link
Contributor

@selul done. I've added the pro changes to https://github.com/Codeinwp/wp-product-review-pro/pull/87

@selul
Copy link
Contributor Author

selul commented Apr 10, 2018

@contactashish13 can we build some unit tests for this new query model. We can generate from phpunit a batch of posts, tags, categories and test different scenarios for query results.

@contactashish13
Copy link
Contributor

@selul added.

I'm not sure if the condition to find by rating has been written correctly in the query model because the test I've written (and commented out) fails. Can you please check?

@contactashish13 contactashish13 added this to the 3.4.9 milestone Oct 9, 2018
@contactashish13 contactashish13 removed this from the 3.4.9 milestone Oct 17, 2018
@DanyCaissy
Copy link

@contactashish13 SHould this issue be closed?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants