Get posts based on meta key/value

The problem It looks like you are saving the data as: $a = array( “13112” ); update_post_meta( $post_id, “article_author”, $a); where this will give you the meta_value a:1:{i:0;s:5:”13112″;} Your first query will give you escaped quotes: LIKE ‘%\”13112\”%’ Method 1 If you save the author array with numbers instead: $a = array( 13112 ); update_post_meta( … Read more

Assign single template to multiple custom post types?

You can filter template_include and pass your custom template as return value depending on your own conditions. Sample code, not tested: add_filter( ‘template_include’, function( $template ) { // your custom post types $my_types = array( ‘photography’, ‘painting’ ); $post_type = get_post_type(); if ( ! in_array( $post_type, $my_types ) ) return $template; return get_stylesheet_directory() . ‘/single-photography.php’; … Read more

How to add custom content template part for a custom post type on main query using a plugin

Background Unfortunately get_template_part() function doesn’t have any suitable filter to achieve what you want. It’s possible to use the get_template_part_{$slug} action hook to inject template parts, however, without any change to your theme or a child theme, the original template part will be added anyway. So this way you’ll not be able to replace existing … Read more

Attaching media to custom posts without editor

At the top of wp-admin/edit-form-advanced.php I see the following code that seems related to the media uploader: if ( post_type_supports($post_type, ‘editor’) || post_type_supports($post_type, ‘thumbnail’) ) { add_thickbox(); wp_enqueue_script(‘media-upload’); } You’ll need to add these yourself. add_thickbox() enqueues both a script and a style, so make sure you hook into print_styles, as print_scripts will be too … Read more