Post Type Label Name

The function register_post_type() takes an argument ‘labels’. This is an array, one of the possible keys is named … tada! … ‘menu_name’. Sample code register_post_type( ‘academias’ , array ( ‘can_export’ => TRUE , ‘exclude_from_search’ => FALSE , ‘has_archive’ => TRUE , ‘hierarchical’ => TRUE , ‘label’ => ‘Academias’ , ‘labels’ => array ( ‘menu_name’ => … Read more

While in “the loop”, detect if a post is the most recent

In addition to @Milo Answer (this avoids a senseless query, because we already got every needed information from the current wp_query): if ( have_posts() ) : while ( have_posts() ) : the_post(); $headline_html_tag = $GLOBALS[‘wp_query’]->current_post === (int) 0 && $GLOBALS[‘paged’] === (int) 1 ? ‘1’ : ‘2’; the_title( ‘<h’.$headline_html_tag.’><a href=”‘.get_permalink().'” title=”‘.the_title_attribute( array( ‘before’ => ‘Permalink … Read more

posts_nav_link() not displaying anything

You need to do a little “hack” to get pagination to work for your custom loop. After you define $myquery, do the following: <?php // globalize $wp_query global $wp_query; // copy $wp_query into a temporary variable $temp_wp_query = $wp_query; // nullify $wp_query $wp_query = null; // move $myquery into $wp_query $wp_query = $myquery; ?> At … Read more

WordPress post tag & custom field

To convert the old custom fields, you can write a plugin that, on activation, fetches all the posts with your custom field name and converts them to tags with the handy wp_set_post_terms. First set up a few constants with your field names and post type. <?php /** * CHANGE THIS! what is your custom field’s … Read more

How to make search for the custom post type?

A better approach is to address the main search query. @Dipesh’s answer is technically correct, but I would suggest using the pre_get_posts action instead to affect the intial query, rather than generating a new one. Much less work! add_action( ‘pre_get_posts’, ‘se39294_search_pre_get_posts’ ); function se39294_search_pre_get_posts( $query ) { if ( $query->is_main_query() && is_search() ) { $query->set( … Read more