How to Sort by Date When Using d-m-Y Format

You need to extend the MySQL-Query directly, as you have to use the MySQL-Function STR_TO_DATE in order to not mess with the pagination etc. You should be able to achieve this with a change in your pre_get_posts like this: add_action( ‘pre_get_posts’, ‘courses_columns_orderby’ ); function courses_columns_orderby( $query ) { if( ! is_admin() ) return; $orderby = … Read more

Help with hierarchical custom taxonomies and permalinks…almost there

Ok, I managed to get it working by hooking into the ‘request’ filter, then checking to see if the last segment is term or not. If it’s not, change the $request var: function alter_the_query( $request ) { $dummy_query = new WP_Query(); // the query isn’t run if we don’t pass any query vars $dummy_query->parse_query( $request … Read more

How do I code access to the built-in UI of a CPT when it’s placed as submenu of another CPT that is protected by role?

From the codex The function which is hooked in to handle the output of the page must check that the user has the required ‘capability’ as well. What it fails to mention is that the check for subpages iterates upwards to its parent. If a user is not capable of accessing TEACHERS, it will not … Read more

960gs different classes on teasers posts

Even better way is to check the current post position in query: global $wp_query; while (have_posts()) : the_post(); $my_class=””; if ( $wp_query->current_post == 0 ) $my_class=” first”; if ( $wp_query->current_post == $wp_query->post_count – 1 ) $my_class=” last”; ?><div class=”post<?php echo $my_class; ?>”><?php … if ( $wp_query->current_post == $wp_query->post_count – 1 ) echo ‘THE CONTENT UNDER … Read more

How can I get the last posts by user role?

I would try the following (not tested) <?php $friends = get_users( array( ‘role’ => ‘friends’ ) ); $friend_ids = array(); foreach( $friends as $friend ) $friend_ids[] = $friend->ID; $news = new WP_Query( array( ‘author’ => implode( ‘,’, $friend_ids ), ‘post_type’ => ‘news’, ‘paged’ => get_query_var(‘paged’) ) ); ?> Note: ‘friends’ is the role ID, not … Read more

Fix custom query pagination without changing site-wide posts-per-page settings

I assume you have a custom post type: publication in functions.php place that code: function mk_parse_query($query) { if ($query->query_vars[‘post_type’] == ‘publication’)) { set_query_var( ‘posts_per_page’, 5 ); } } if( !is_admin() ) { add_filter(‘parse_query’,’mk_parse_query’); } Similar code works for me, but in my case I was struggling with 404 on custom taxonomies paged urls. Hope this … Read more

How can I customize “Pages” admin (edit.php) and “Edit Page” admin (post.php) for bulk edit of custom content type?

Do not edit core files. . 1. Assuming you have a registered a custom post type called biblio, you can add and remove “stuff” within your functions.php. For instance this removes some meta boxes from ‘biblio’ function remove_default_page_screen_metaboxes() { global $post_type; remove_meta_box( ‘commentstatusdiv’,’biblio’,’normal’ ); // Comments Metabox remove_meta_box(‘commentsdiv’,’biblio’,’normal’); // Comments remove_meta_box( ‘trackbacksdiv’,’biblio’,’normal’ ); // Talkback … Read more