WordPress.org

Ready to get started?Download WordPress

Forums

Query Multiple Taxonomies
ot working with checkbox (10 posts)

  1. ArenAK
    Member
    Posted 3 years ago #

    Hi,

    I'm using this code for plugin QMT(Query Multiple Taxonomies) with checkbox, but it's not working:

    $out .=
    			html( 'li',
    				 get_taxonomy( $taxonomy )->label . ': '
    				.scbForms::input( array(
    					'type' => 'checkbox',
    					'name' => $taxonomy,
    					'values' => scbUtil::objects_to_assoc( $terms, 'slug', 'slug' ),
    					'selected' => qmt_get_query( $taxonomy ),
    				) )
    			);

    The code was this originally in query-multiple-taxonomies/widget.php:

    $out .=
    			html( 'li',
    				 get_taxonomy( $taxonomy )->label . ': '
    				.scbForms::input( array(
    					'type' => 'select',
    					'name' => $taxonomy,
    					'values' => scbUtil::objects_to_assoc( $terms, 'slug', 'slug' ),
    					'selected' => qmt_get_query( $taxonomy ),
    				) )
    			);

    Can anybody tell me how to solve this problem?

  2. scribu
    Member
    Plugin Author

    Posted 3 years ago #

    If only it were that easy... there are several things that need to be changed in order for this to work. Stay tuned.

  3. ArenAK
    Member
    Posted 3 years ago #

    Thank you, scribu. I'm surely keeping an eye on this wonderful plugin.

    I noticed that you used $wp_query->get( $qv ) to get the user-required taxonomy values.
    So I think the code must set the $wp_query somewhere after the user selects values from the forms in the sidebar, but where is the code for that? I didn't find it, could you tell me where is it?
    Thanks in advance.

  4. scribu
    Member
    Plugin Author

    Posted 3 years ago #

    After trying to implement this, I'm not so sure I understand what you're trying to do. How should the taxonomy drilldown work with checkboxes?

  5. ArenAK
    Member
    Posted 3 years ago #

    I realized that QMT works with radio box:

    $out .=
    			html( 'li',
    				 get_taxonomy( $taxonomy )->label . ': '
    				.scbForms::input( array(
    					'type' => 'radio',
    					'name' => $taxonomy,
    					'values' => scbUtil::objects_to_assoc( $terms, 'slug', 'slug' ),
    					'selected' => qmt_get_query( $taxonomy ),
    				) )
    			);

    So it means it could display the taxonomies with either lists, dropdowns, or radios.
    Instead of those there, what I want to do is to display the taxonomies with checkbox, so the user could select items with value "football" OR(not and) “basketball" under the same taxonomy "ball".

  6. Patrick Daly
    Member
    Posted 3 years ago #

    Has anyone revisted this?

    Just to further clarify, we're looking for an option to replace the hyperlinks in the "list" form with checkboxes. So the widget options for Mode would be "lists, dropdowns, checkboxes".

    The checkboxes mode would output similarly to the lists mode, but instead of plus and minus signs it would use checkboxes.

  7. totels
    Member
    Posted 3 years ago #

    With the method WP uses to handle queries at the moment it is not possible to use checkboxes easily. It effectively would require writing a query translator, WP expects requests for multiple items to be in the format of taxonomy_name=slug1,slug2,slug3, which is not possible with checkboxes (checboxes, all using the same name would look like: taxonomy_name=slug1&taxonomy_name=slug2&taxonomy_name=slug3).

    Javascript could be used to manipulate the query pre-submit, but that's not very elegant.
    jQuery(':checkbox:checked').map(function() { return this.id }).get().join(',');

  8. adige72
    Member
    Posted 3 years ago #

    So is it possible to select multiple terms per taxonomy when shown as dropdownbox or checkboxes?

    I have a taxonomy called "Cities" and terms are Paris and New York.

    And what i'd like to do is that when i select both Paris and New York and then click Submit button, i would like to be able to show both Paris and New York related posts in search result page. Is it possible?

  9. Patrick Daly
    Member
    Posted 3 years ago #

    The best implementation would be to offer a submit button OR use an Ajax query to automatically update the query on every checkbox change. Integrating Ajax with a WP query doesn't seem very simple though.

  10. totels
    Member
    Posted 3 years ago #

    @adige72 at the moment what you want isn't possible, I am planning on contributing some code to rectify this, but I won't have time for at least another month

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic