bradical911
Forum Replies Created
-
Forum: Hacks
In reply to: Alphabetical ordering with Query Posts and 2 Meta Keysthank you bcworks, your advice is much appreciated – the main thing for me is being pointed in the right direction…will post back results if successful
Forum: Hacks
In reply to: Alphabetical ordering with Query Posts and 2 Meta KeysIm now reading this http://codex.wordpress.org/Class_Reference/wpdb
sounds like the right place to startForum: Hacks
In reply to: Alphabetical ordering with Query Posts and 2 Meta Keysthanks, I’m fine with “wordpress” PHP but SQL commands not so as I’m more a designer than dev although interested to learn more, I found some code I’ve started to customise but I’m not really sure what I’m doing
The aim is to order by post title, then order by 2 meta keys – alphabetically. The posts come from custom post I’ve set up called “plant-catalogue”.
So not this:
Title
– B (Key 0)
– A (Key 1)This:
Title
– A (Key 0)
– B (Key 1)<?php $querystr = " SELECT * FROM $wpdb->posts LEFT JOIN $wpdb->postmeta AS eventdate ON( $wpdb->posts.ID = eventdate.post_id AND eventdate.meta_key = 'Species' ) LEFT JOIN $wpdb->postmeta AS eventtime ON( $wpdb->posts.ID = eventtime.post_id AND eventtime.meta_key = 'Variety' ) LEFT JOIN $wpdb->term_relationships ON($wpdb->posts.ID = $wpdb->term_relationships.object_id) LEFT JOIN $wpdb->term_taxonomy ON($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id) WHERE $wpdb->term_taxonomy.term_id = 3 AND $wpdb->term_taxonomy.taxonomy = 'plant-catalogue' AND $wpdb->posts.post_status = 'publish' ORDER BY eventdate.meta_value, eventtime.meta_value ASC"; ?>Forum: Hacks
In reply to: Alphabetical ordering with Query Posts and 2 Meta Keysthank you bcworkz that helps a lot in my understanding of the situation, i was starting to try and work out a solution with WP_Query but seems I’m wasting my time?
Some untested “guess” code that i thought might need work but eventually work…
$args = array( 'post_type' => 'plant-catalogue', 'meta_query' => array( array( 'key' => 'Species', 'key' => 'Variety', 'order' => 'ASC', ), ), 'orderby' => 'title meta_query', 'order' => 'ASC', ); $query = new WP_Query( $args );Forum: Hacks
In reply to: Alphabetical ordering with Query Posts and 2 Meta KeysIs it possible to do something here with meta_query ?
Forum: Hacks
In reply to: Query posts sort by title and a meta keyIve got this far see new post here:
Forum: Hacks
In reply to: Search not displaying results for multiple word queriesHi BCWorks,
Thank for the reply, so its ANDing the search times, ok that makes sense.
As I cant predict exactly what a user is going to type it only really works if it is doing “Ors” otherwise it fails as a search which makes it pretty useless especially when the words themselves are within the website maybe just not in the same order in the same place (could be anywhere in title, custom meta, content), just not that “exact phrase”.
Do you know if there any plugins that get round this or can the search form itself be altered or functions.php have anything added.
Funnily enough when I search for answers on this i don’t get much luck either.
FYI my search form:
<form id="search_form" action="http://www.champernowne.co.uk/beta/" method="get"> <input class="search" type="text" name="s" value="search..." onblur="if (this.value == '') {this.value = 'search...';}" onfocus="if (this.value == 'search...') {this.value = '';}" /> <input type="hidden" name="post_type" value="plant-catalogue" /> <input class="search-button" id="searchsubmit" type="submit" alt="Search" value="GO!" /> </form>Forum: Hacks
In reply to: Search not displaying results for multiple word queriesif it helps get a few responses here is my code for search.php – nothing particularly exciting…
<?php get_header(); ?> <section> <h1>Results for - "<?php the_search_query(); ?>"</h1> <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <article id="post-<?php the_ID(); ?>"> <h2 class="page-title" itemprop="headline"><a href="<?php echo get_permalink(); ?>"><?php the_title(); ?></a></h2> <?php if (has_post_thumbnail() ) { // show small pic //echo "small pic"; echo "<div class=\"thumbnail-post thumbnail-small\">"; the_post_thumbnail( 'small' ); echo "</div>"; } else {} ?> <?php echo the_meta(); ?> <p>▸ <a href="<?php echo get_permalink(); ?>">Read More</a></p> <?php endwhile; else : ?> <h1><?php _e( 'Page Not Found!'); ?></h1> </article> <?php endif; ?> </section> <aside> <?php get_sidebar(); ?> </aside> <?php get_footer(); ?>Forum: Themes and Templates
In reply to: Get posts – remove duplicate titles from loopA friend offered this solution which works nicely. However he points out that:
The problem with that is there will be a load of unnecessary looping. Say you get 1000 rows back from the database but it only actually outputs 2.
For me it works fine on a small site but would be interested in anything that can reduce querys to the DB.
<ul> <?php /** * Create an array to hold all of the post titles */ $post_titles = array(); $lastposts = get_posts('&post_type=catalogue&orderby=title&order=ASC&numberposts=-1'); foreach($lastposts as $post) : $post_title = get_the_title(); if(!in_array($post_title, $post_titles)) : /** * Add the post title to the array */ array_push($post_titles, $post_title); setup_postdata($post); // somehow remove duplicates titles? ?> <li> <a href="?s=<?php the_title(); ?>&post_type=catalogue"> <?php the_title(); ?> </a> </li> <?php endif; endforeach; ?> </ul>