WordPress.org

Support

Support » Plugins and Hacks » Query Multiple Taxonomies » [Resolved] Query Taxonomies AND custom fields

[Resolved] Query Taxonomies AND custom fields

Viewing 12 replies - 1 through 12 (of 12 total)
  • Stefan

    @axenstar86

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

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

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

    as I would like some work to be done!

    thanks
    Andy

    Bump for help!

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

    Thank you!

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

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

    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>

    “$custom_fields” should be “$ratings”

    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!

    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;
    }

    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!

    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.

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘[Resolved] Query Taxonomies AND custom fields’ is closed to new replies.
Skip to toolbar