Any way to include custom fields in WP_Query results?

You may want to hook somewhere in the gazillion hooks available in wp-includes/query.php. I would suggest something like this: function my_always_get_post_custom( $posts ) { for ( $i = 0; $i < count($posts); $i++ ) { $custom_fields = get_post_custom( $posts[$i]->ID ); $posts[$i]->custom_fields = $custom_fields; } return $posts; } add_filter( ‘the_posts’, ‘my_always_get_post_custom’ ); In this way you … Read more

Upcoming Event: How do I sort database by custom date field, but ignore past dates?

You’re pretty close, but I wouldn’t be distracted by the ‘scope’ meta key. The following is untested. <?php $args = array( ‘post__not_in’ => array($donotrepeat), “post_type” => ‘event’, ‘meta_key’ => ‘_event_start_date’, // name of custom field ‘orderby’ => ‘meta_value’, “order” => ‘ASC’, “posts_per_page” => 1, ‘meta_query’ => array( array( ‘key’ => ‘_event_start_date’, ‘value’ => date(‘Y-m-d’), ‘compare’ … Read more

Custom Post Type Navigation on Custom Field

For previous and next post links to work, you need to hook on to the get_*_post_* filters and modify the query to actually sort the posts using your custom field. I hope the code below will work for you. For Previous post link add_filter(‘get_previous_post_join’, ‘wpse96670_get_previous_post_join_custom_sort’); add_filter(‘get_previous_post_where’, ‘wpse96670_get_previous_post_where_custom_sort’); add_filter(‘get_previous_post_sort’, ‘wpse96670_get_previous_post_sort_custom_sort’); function wpse96670_get_previous_post_join_custom_sort($join) { global $wpdb; return … Read more

How to Display Custom Meta Box only on Specific Page IDs

A simple and cleaner solution would be to use !in_array ex: function mf_1_remove_meta_boxes() { if( !is_admin() && !isset( $_GET[‘post’] ) ) return; if( !in_array($_GET[‘post’], array(‘194′,’185′,’2’) ) ) remove_meta_box( ‘mf_1’, ‘page’, ‘normal’ ); } this way you can just add the ids in the array and as many as you want

Assigning the same custom meta box to multiple post types

Yes, you need to edit your video_add_box() function in order to make an array with the post type you need to show that box. $postypes = array(‘type1’, ‘type2’, ‘type3’); foreach ( $postypes as $postype) { add_meta_box( ‘video_information’, ‘Video Information’, ‘video_information’, $postype ); } You can read more in codex: http://codex.wordpress.org/Function_Reference/add_meta_box

How to enable Custom Fields that are disabled by theme?

Create a Child Theme, Plugin or Must Use plugin, and use add_post_type_support: <?php /* Plugin Name: Add CF to CPTs */ add_action( ‘plugins_loaded’, ‘add_cpt_support_wpse_116891’ ); function add_cpt_support_wpse_116891(){ # See /wp-admin/edit.php?post_type=SLUG add_post_type_support( ‘SLUG-POST-TYPE-1’, array( ‘custom-fields’ ) ); add_post_type_support( ‘SLUG-POST-TYPE-2’, array( ‘custom-fields’ ) ); add_post_type_support( ‘SLUG-POST-TYPE-3’, array( ‘custom-fields’ ) ); }

Custom fields in Permalinks?

Use add_rewrite_tag( $tag, $regex ); to register a rewrite tag for the custom field. Filter post_type_link to replace the rewrite tag. The second argument is the post object, so you have always access to the post ID. For a sample implementation see my plugin T5 Rewrite. It does exactly that in the class T5_Rewrite_Tag_Custom.