Using previous_post_link and next_post_link to wrap around post sequence

Add following custom functions in functions.php file and instead of calling previous_post_link and next_post_link functions call custom_next_post_link and custom_previous_post_link custom functions respectively. function custom_adjacent_post_link( $format, $link, $in_same_cat = false, $excluded_categories=””, $previous = true ) { if ( $previous && is_attachment() ) $post = get_post( get_post()->post_parent ); else $post = get_adjacent_post( $in_same_cat, $excluded_categories, $previous ); if … Read more

How to solve suspected memory issue in custom WordPress loop?

There are approx. 10,000 items returned by the query. That’s your problem right there. No matter what you do inside the loop, WordPress is still loading 10,000 post objects into memory. Batch it up and sprinkle a little magic in your query arguments: $args = array( ‘fields’ => ‘ids’, // MAGIC! Just get an array … Read more

How do I add a custom post type to the Featured Content in twenty fourteen theme?

The twentyfourteen_get_featured_posts filter: It took some digging, to figure out how the twentyfourteen_get_featured_posts filter is used in the TwentyFourteen theme 😉 The featured content is fetched with: $featured_posts = twentyfourteen_get_featured_posts(); but this function is only this single line: return apply_filters( ‘twentyfourteen_get_featured_posts’, array() ); so where’s the meat? We find it in the Featured_Content class, starting … Read more

Priority of Meta Box for Custom Post Type

Where you have the parameter ‘normal’ eg. the context parameter change that to read ‘core’. add_meta_box(‘cpt_meta’, ‘Meta Box’, ‘cpt_meta’, ‘cpt_function’, ‘core’, ‘high’); The default meta boxes are registered as core and are listed first, followed by the ‘normal’ context. The docs don’t actually say you can do it but I have done without any problems. … Read more

How do I redirect all 404 errors of a specific post type to another URL?

It looks like template_redirect is as far up the WordPress action chain you can go while still being able to detect that a 404 error is being thrown. This action will trigger before any template files would be loaded so it will happen before loading unnecessary resources. You can try adding this into your /wp-content/themes/yourtheme/functions.php … Read more

Including a custom post type in the Archives widget

The Archive widget is using wp_get_archives() to display the archive. If you want to target all the wp_get_archives() functions, you can use the getarchives_where filter to add your custom post type: add_filter( ‘getarchives_where’, ‘custom_getarchives_where’ ); function custom_getarchives_where( $where ){ $where = str_replace( “post_type=”post””, “post_type IN ( ‘post’, ‘videos’ )”, $where ); return $where; } If … Read more