Created
July 20, 2014 01:48
-
-
Save yojance/c795437c1d40169002e0 to your computer and use it in GitHub Desktop.
OptionTree Custom Post Type Select Option Type
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// OptionTree Custom Post Type Select Option Type | |
// Example code when being used as a Metabox or | |
// Exported OptionTree file to be used in Theme Mode | |
array( | |
'id' => 'spyr_demo_custom_post_type_select', | |
'label' => __( 'Custom Post Type Select', 'text-domain' ), | |
'desc' => __( 'Your description', 'text-domain' ), | |
'type' => 'custom-post-type-select', | |
'section' => 'your_section', | |
'post_type' => 'movie', | |
) | |
// Get the ID value saved on Theme Options Page | |
$spyr_demo_custom_post_type_select = ot_get_option( 'spyr_demo_custom_post_type_select' ); | |
// Get the ID value saved for a Page, Post or CPT ( Within the loop ) | |
$spyr_demo_custom_post_type_select = get_post_meta( $post->ID, 'spyr_demo_custom_post_type_select', true ); | |
// Get the Post's title | |
$title = get_the_title( $spyr_demo_custom_post_type_select ); | |
// Get the permalink | |
$link = get_permalink( $spyr_demo_custom_post_type_select ); | |
// Override Custom Post Type via code | |
add_filter( 'ot_type_custom_post_type_select_query', 'spyr_ot_type_cpt_select_query_set_cpt', 10, 2 ); | |
function spyr_ot_type_cpt_select_query_set_cpt( $query, $field_id ) { | |
if( 'spyr_demo_custom_post_type_select' == $field_id ) { | |
return array_merge( $query, array( 'post_type' => 'movie' ) ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment