Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

live ajax sorting of custom taxonomies for a custom post-type WordPress

  • SOLVED

[[LINK href="http://www.cocosuites.com/en/suites/Spain/Barcelona"]]http://www.cocosuites.com/en/suites/Spain/Barcelona[[/LINK]]

The above link is probably the closest example to what I am after.

Project details:

I have a custom post-type 'photo gallery', which has a few custom taxonomies. I use one taxonomy as a 'photo category' that is hierarchical, and a few other non hierarchical taxonomies such as 'photo tags, equipment, camera settings, etc'.

I have no problem setting everything up on the site to function exactly as it should be done.

What I need:
I need the ability to have a widget built that will allow me to insert multiple taxonomy selection boxes onto my pages.

I then need that taxonomy selection box to act just like the site above does, where the user can select a taxonomy, or multiples, and have the center content auto display only those posts that fit the taxonomy choices.

I have no problem using css/js myself and outputting the taxonomy into the div class of each post, and doing sorting that way. I do have a problem when the system involves multiple choices, and I doubt this would be the best approach. I know virtually nothing about ajax yet, other than to know it's probably a good way to go.

What I don't need:
I don't need any design work. I simply need the code to insert into my own templates that will allow the dynamic filtering.


I have zero idea how much work a project like this would entail as I have yet to see a wordpress site doing this. (well there is a new theme coming out shortly that does, but I am tired of waiting lol).

I'm open to estimates and the best way to proceed on a project like this.

thanks everyone

Answers (1)

2010-11-06

Michael Fields answers:

The best solution I can think of at this point in time revolves around mixing to bits of code together. First would be from Scribu. His plugin allows you to query for multiple taxonomies at the same time. FYI it appears that functionality similar to this will be added in WordPress v3.1.

Here's the link: http://scribu.net/wordpress/query-multiple-taxonomies

The second part involves sending the $_GET request to wp-admin/admin-ajax.php to display the results. Here is an example of such code: http://wordpress.pastebin.com/eBup7qkb

Best wishes,
-Mike


shawn comments:

Thanks Michael

Yes I am familiar with qmt plugin. I'm actually hoping to come up with a solution that I can package into my theme itself for commercial purposes.

I'll go and read the pastebin to see if I can understand what it is doing.


Michael Fields comments:

You can really bundle any plugin inside a theme by using a conditional statement within functions.php. Some thing like this should illustrate:


if( !function_exists( plugin_specific_function() ) ) {
require_once 'main_plugin_file.php';
}


I've done some testing with this process and it works rather well.

Although this is possible, I would suggest that you leave the plugin code in a plugin, or wait for this functionality to be included into core. It's actually in trunk at the moment, you could hypothetically conditionally include the query objects... but IMO it's best to wait until they have undergone beta testing.


shawn comments:

OK, best that I just hold off for now then. I have kept up with the trac on this topic, and can't wait for the new functionality.

On a side note:

How much would you charge me to modify your 'selective hierarchical page navigation' walker code to work on my custom post-type 'photogallery' which is actually based on posts, not pages?

I created a custom hierarchical taxonomy to act as a category system for my gallery, and want to put a widget in the sidebar for the gallery showing categories, just like your custom walker does.

That should get me by for now at least.


Michael Fields comments:

Not sure... I was asked via the WordPress support forums to include similar functionality into my taxonomy images plugin. At first I was thinking that it would be a great idea... quite honestly it is. But there's a significant problem with implementing a walker like this for a taxonomy.

Posts can have more than one term applied to them.

Hierarchical posts can only ever have only one parent.

Basically there is the possibility that one post will belong to more than one taxonomy where the walker would generate confusing results. I have tried, but found it to be really hard to actually force a post_type to use only one term from a given taxonomy. I've gotten really close, but haven't really figured out how to properly hook into the "quick edit" forms which (last time I checked) are generated via javascript.

When all is considered, this is not really functionality that I want to build and then support as it will 'break' where posts have more than one term associated with them.


shawn comments:

easy temp solution that would work for me would be, if a post belongs to more than one category, then assign it to the first category it is listed in. I can just explain it to my users that 'it's just the way it works so deal with it...'

Or.....

Assign the image to the category slug being displayed for those that belong to more than 2?