logo

John Cotton

Website


Written in response to Theme localization in a query...:

Although Francisco's solution fixed Josh's problem, his answer is technically incorrect.

There is no need to assign the return value of __() to a variable prior to use - the return value can be used like any return value from any other function.

The problem with Josh's code was the incorrect use of concatenation within his parameters.

The solution I offered:

'category_name'    	=>  __('Our Friends', 'mytheme'),


would have fixed that without the (albeit minor) overhead of creating a new variable that only gets used once.

link

Written in response to How to get a similar structure?:

For those interested, here is what BadNews got in the end:

A custom post type of game_post with custom taxonomies of game_ratings, game_genres, game_publishers and game_developers. The custom post type wasn't completely necessary, but made things clearer in the queries, kept the custom taxonomies out of other post types and enabled the use of single-game_post.php theme file, making cleaner code.

(Standard) Post categories of cheats, hints, unlockables and Easter Eggs were created.

The "glue" was another custom taxonomy called game_name in which each game_post had a matching entry. This taxonomy was applied to both the game_post and each related standard post (ie cheats, hints etc).

Then in single-game_post.php this function:


function get_related_posts( $category, $slug ) {

$args = array( 'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'category',
'field' => 'slug',
'terms' => array( $category )
),
array(
'taxonomy' => 'game_name',
'field' => 'slug',
'terms' => array( $slug )
)
));

$the_query = new WP_Query( $args );

if( $the_query->post_count > 0 ) {
// loop through and output as desired
}

wp_reset_postdata();
}


could be called by this code:

       
// Get the 'glue' game_name taxonomy
$game = wp_get_object_terms( $post_id, 'game_name');

// Use the glue to retrieve related posts
get_related_posts( 'unlockable', $game[0]->slug );
get_related_posts( 'cheat', $game[0]->slug );
get_related_posts( 'hint', $game[0]->slug );





link

Lawrence Krubner had responses to this.

Written in response to Custom Wordpress Search Results Page (Only comments, not posts):

Edit the search.php file in your theme to replace the existing posts loop with something like this:


$comments = $wpdb->get_results("SELECT * FROM {$wpdb->comments} WHERE comment_content LIKE '%{$s}%'");

if($comments) {
foreach($comments as $comment) {
echo '<h1>'.$comment->comment_content.'</h1>';
}
}


The SELECT query could be made much more detailed of course and the output would need to be more sophisticated (you'll get the ID for the post back for example so you could easily link to the original post), but hopefully you get the idea..

John

link