Distinction on meta value on pre_get_posts

DISCLAIMER : Not a WordPress Expert, Just an old MySQL DBA Here is your original generated SQL SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts INNER JOIN wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id) WHERE 1=1 AND wp_posts.post_type=”post” AND (wp_posts.post_status=”publish” OR wp_posts.post_status=”private”) AND ( ( wp_postmeta.meta_key = ‘_position’ AND CAST(wp_postmeta.meta_value AS CHAR) > ‘0’ ) ) GROUP BY wp_posts.ID, wp_postmeta.meta_value … Read more

Arrange and separate posts

You can do some tricky thing with PHP. Here is the algorithm you could use. Query posts to get posts as alphabetical order. for/while loop starts. $t = Get first character of the title string. $temp = ” empty string. if $t != $temp echo $t. set $t = $temp. endfor/endwhile. Hope it make sense. … Read more

posts_groupby problem

Your filter will result in SQL query with GROUP BY statement but without aggregate function. This will result in displaying only the first row that appear in the group that match your query and omitting the subsequent rows. Read this question for more details. If you want to order your results by post_type, you can … Read more

What’s the easiest way to change the default landing page for BuddyPress groups?

[Edit – My original answer will only work in the upcoming BP 1.6] Versions of BuddyPress from 1.6 onwards function bbg_change_group_default_extension( $default ) { return ‘forum’; } add_filter( ‘bp_groups_default_extension’, ‘bbg_change_group_default_extension’ ); Versions of BuddyPress prior to 1.6 For the moment, you’ll have to use something like the following, which is a modified version of bp_core_new_nav_default() … Read more

Select All in Parent Category, Group by Child Category?

Here’s a straight up simple solution. Requires you to have the most recent version of WordPress though. (or at least 4.1) Using nested taxonomy query. Taking what you have, and just adding to it a bit. $args = array( ‘post-type’ => ‘episode’, ‘post-status’ => ‘publish’, ‘posts_per_page’ => 4, ‘tax_query’ => array( ‘relation’ => ‘AND’, array( … Read more

Display category posts grouped by taxonomy

I’ve found a solution! <?php // Get current Category $get_current_cat = get_term_by(‘name’, single_cat_title(”,false), ‘category’); $current_cat = $get_current_cat->term_id; // List posts by the terms for a custom taxonomy of any post type $post_type=”myposttype”; $tax = ‘mytaxonomy’; $tax_terms = get_terms( $tax, ‘orderby=name&order=ASC’); if ($tax_terms) { foreach ($tax_terms as $tax_term) { $args = array( ‘post_type’ => $post_type, “$tax” … Read more