WordPress.org

Forums

Query Multiple Taxonomies
[resolved] [closed] Query Taxonomies AND custom fields (13 posts)

  1. Axenstar86
    Member
    Posted 2 years ago #

    Hi there,

    I'd like to filter by multiple terms together with custom fields ( especially min - max range).

    Is there any solution around to extend this plugin with a custom field search?

    Regards
    Stefan

    http://wordpress.org/extend/plugins/query-multiple-taxonomies/

  2. Axenstar86
    Member
    Posted 2 years ago #

    I combined QMT with Custom Query Fields Plugin. Works great!

  3. Rics1983
    Member
    Posted 2 years ago #

    How did you combined them? I'm interested too into this!

  4. Maraki
    Member
    Posted 2 years ago #

    Axenstar86, could you please email me at neodjandre @gmail. com

    as I would like some work to be done!

    thanks
    Andy

  5. Rics1983
    Member
    Posted 2 years ago #

    Bump for help!

    @Maraki Did you received some infos about to combine this two plugins from Axenstar86?

    Thank you!

  6. Axenstar86
    Member
    Posted 2 years ago #

    Hey all, I'll post some example code later this day.

  7. Rics1983
    Member
    Posted 2 years ago #

    Thank you Axenstar86, you don't know how much i can appreciate this!
    Thank you!

  8. Axenstar86
    Member
    Posted 2 years ago #

    So guys here is my code to query custom fields AND taxonomies:

    1st I made some changes to the qmt-template "checkboxes.html" and "dropdowns.html" (as I use checkboxes and dropdowns for my form)

    checkboxes:

    <form method="get" action="{{base-url}}" class="custom taxonomy-drilldown-checkboxes">
    	{{#taxonomy}}
    	<div id="terms-{{taxonomy}}">
    		<ul>
    			{{{term-list}}}
    		</ul>
    	</div>
    	{{/taxonomy}}

    dropdowns:

    <form method="get" action="{{base-url}}" class="taxonomy-drilldown-dropdowns">
    	<ul>
    		{{#taxonomy}}
    		<li>
    
    			<select id="qmt-{{name}}" name="{{name}}">
    				<option value=''>{{{any-text}}}</option>
    				{{{term-list}}}
    			</select>
    		</li>
    		{{/taxonomy}}
    	</ul>

    As I'm going to extend the forms with custom fields, I'lll close it later.

    Now in my wordpress theme template ( in my case : archive.php) I built this extended form Just change the field names and keys etc that it fits your needs:

    <!-- Query Multiple Taxonomies AS CHECKBOX -->
    
    		<?php
    			the_widget('Taxonomy_Drill_Down_Widget', array(
    			'title' => '',
    			'mode' => 'dropdowns',
    			'taxonomies' => array( 'tax1, tax2') // list of taxonomy names
    			));
    		?>
    
    <!-- Query Multiple Taxonomies AS DROPDOWN -->
    
    	<?php
    		the_widget('Taxonomy_Drill_Down_Widget', array(
    		'title' => '',
    		'mode' => 'checkboxes',
    		'taxonomies' => array( 'tax3, tax4') // list of taxonomy names
    		));
    	?>
    
    <!-- Now we combine the form with custom fields -->
    
    <?php $custom_fields = get_meta_values( 'cf_key', 'cf_value' ); // Get all Meta Values associated with Key ?>
    
    <!-- Get CF Min Value -->
    
    <select name="album_rating_min" id="rating_min"> 
    
    	<option value="">-</option>
    	<?php foreach($ratings as $rating){
    		echo '<option value="' . $rating . '"' . ($rating == $_GET["album_rating_min"] ? ' selected="selected"' : '') . '>' . $rating . '</option>';  //Echo all Rating Values as Options
    	} ?>
    
    </select>
    
    <!-- Get CF Max Value -->
    
    <select name="album_rating_max" id="rating_max"> <!-- Get Rating Max Value -->
    
    	<?php foreach($ratings as $rating){
    		echo '<option value="' . $rating . '"' . ($rating == $_GET["album_rating_max"] ? ' selected="selected"' : '') . '>' . $rating . '</option>';  //Echo all Rating Values as Options
    	} ?>
    
    </select>
    
    <!-- Let's submit our combined form -->
    
    <input type="submit" value="filter" />
    
    <!-- Close the form started in the qmt-templates -->
    
    </form>
  9. Axenstar86
    Member
    Posted 2 years ago #

    "$custom_fields" should be "$ratings"

  10. camilodelvasto
    Member
    Posted 2 years ago #

    Axenstar86, thank you, I'm also working on this feature... quick question: did you use "get_meta_values" from this post: http://wordpress.stackexchange.com/questions/9394/getting-all-values-for-a-custom-field-key-cross-post ? or did you develop another one?
    Thanks!

  11. Axenstar86
    Member
    Posted 2 years ago #

    Yeah I believe it's the same. To be sure here is my code:

    function get_meta_values( $key = '', $type = '', $status = 'publish' ) {
        global $wpdb;
        if( empty( $key ) )
            return;
        $r = $wpdb->get_col( $wpdb->prepare( "
            SELECT DISTINCT pm.meta_value FROM {$wpdb->postmeta} pm
            LEFT JOIN {$wpdb->posts} p ON p.ID = pm.post_id
            WHERE pm.meta_key = '%s'
            AND p.post_status = '%s'
            AND p.post_type = '%s'
    		ORDER BY ( CASE pm.meta_value
    
    			WHEN '10' THEN 1
    			WHEN 'Keine Bewertung' THEN 999
    
    			ELSE 100 END) ASC, pm.meta_value DESC
    
        ", $key, $status, $type ) );
        return $r;
    }
  12. Rics1983
    Member
    Posted 2 years ago #

    That's super Axenstar!
    I'll try to implement it with lists, as i'm using them for my qmt widget.

    Thank you so much, i'll report if i'll achieve my goal!

  13. camilodelvasto
    Member
    Posted 2 years ago #

    I also implemented it using lists and is working pretty well!

    I HAD to make some minor changes to the core, since there was a problem with pagination and the query was not working well. Don't know if it's only me, but here is what worked for me. In core.php, line 147, from:

    $query[ $taxonomy ] = trim( implode( '+', $value ), ',' );

    to:

    $query[ $taxonomy ] = trim( implode( ',', $value ), ',' );

    I did the same change in walkers.php (replacing "+" with ",") in lines 41 and 84.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Query Multiple Taxonomies
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic