Ummm... What do I understand by queries anyway? And how do I know if I need this or not? Let's try and get the concept cleared. I am hoping you are aware of the fact that all the pages, posts, users, categories or rather any soft data entered in your website are stored in your databases. Your data are not dumped in one single place, they are rather segregated into tables of a database. Queries are requests that a developer makes to a database asking it to return the values stored in its tables. Coming down to WordPress, simple functions like get_posts(), get_post_meta(), get_user_meta(), get_terms() etc. all make queries to your database asking them to return the posts that you saved, or metadata of a post you created, categories or users and their metadata. For a basic example, when I pass get_user_meta( 35, 'first_name', true), I am basically asking hey! `wp_usermeta` table from the database `my_database_name` ( whatever was set in your `wp-config.php` file ), return the first name of the user with 35 ID number. Now, coming down to WCMp, you will know you need to modify a query when you are not really satisfied say, for example, with the way vendors are displayed or you wanna fidget around the categories/ tags provided to the vendor when they submit their products or the way WCMp widgets are displaying vendors or their product categories or something similar to that. That is when you will need to MODIFY QUERIES and the good news is: We have Hooks and Filters for those.
Modify tags displayed for vendors in the add-product page
By default, we allow vendors to choose from a maximum of 45 tags and the tags are displayed even if they do not have any product assigned to them. The tags that have the highest number of products assigned to them are displayed first and the least are displayed last.
The following code modifies the default way it is displayed.
Lets get down to the nitty gritty details of the arguments passed in the above code.
- 'hide_empty'- Has been set to true. This prevents tags that do not have any products assigned to them to be displayed to vendors. Setting it to false will display all the tags irrespective of products assigned to it.
- 'orderby'- This is a clause that filters out the results on basis of certain parameters. By default, we sort the results by the number of products assigned to it - 'count', determines the same.
- 'order'- This determines whether the results are to be shown in ascending (ASC)/ descending (DESC) order.
Modify the way vendors are displayed on the vendor list page
All vendors registered on your website are displayed on the vendor list page according to the dates they've registered. But, going by our experience, few of our clients aren't really satisfied with the date sorting procedure or would want to make additions to the filtering. In such a case, you can modify the accepted parameters. An example of this is shown in the snippet below
Again, the parameters we've passed are the ones we've already had a clear discussion on in our above section. However you can read more about these parameters and all the accepted arguments in this codex documentation.
That's it folks! Easy as pie!