Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Justin Sternberg

    (@jtsternberg)

    Version 1.2.7 does just that automatically, and includes two new template tags to pull in the photo. dw_get_instagram_image works just like get_the_post_thumbnail and dw_instagram_image just like the_post_thumbnail, except they grab/display the imported Instagram image.

    Thread Starter Jamie

    (@digitalchild)

    Hello,

    Thanks for the reply. I was meaning being able to assign it to a custom field that I define not one already in the plugin. The reason for this is I have a theme that has a custom post type for photos and doesn’t use the featured image but its own custom field.

    This would mean you select ‘store in custom field’ and then type the custom field instead of selecting save photo to posts featured image.

    What I ended up doing was writing a cron job that runs once a day to do this. I have attached the code incase someone needs it. It would need to be modified to suit but gets the job done!

    function instagram_feature_image_change() {
    
    	$args = array(
    		'post_type' => 'photo',
    		'post_status' => 'publish',
    		'posts_per_page' => -1,
    		'tax_query' => array(
    			array(
    			      'taxonomy' => 'photo-category',
    			      'field' => 'slug',
    			      'terms' => 'instagram'
    		      	)
    		     )
    	);
    
    	$posts = get_posts($args); 
    
    	foreach ($posts as $post) {
    		$post_thumbnail_id = get_post_thumbnail_id( $post->ID );
    		update_post_meta( $post->ID, '_custom_image_name', $post_thumbnail_id );
    	}
    }
    
    add_action( 'instagram_feature_update', 'instagram_feature_image_change' ); 
    
    if( !wp_next_scheduled( 'instagram_feature_update' ) ) {
       wp_schedule_event(time(), 'daily', 'instagram_feature_update');
    }

    If you could add the feature I could remove this code. If not, someone might find this useful.

    Plugin Author Justin Sternberg

    (@jtsternberg)

    With the latest update to the plugin, you could easily filter the ‘update_post_meta’ action to duplicate the attachment ID to another meta key. You would do so like:

    add_filter( 'update_post_metadata', 'dsgnwrks_duplicate_meta_to_new_key', 10, 5 );
    function dsgnwrks_duplicate_meta_to_new_key( $null, $post_id, $meta_key, $meta_value, $prev_value ) {
    
    	if ( 'instagram_image_id' == $meta_key ) {
    		// duplicate meta to another meta key
    		update_post_meta( $post_id, '_custom_image_name', $meta_value, $prev_value );
    	}
    
    	// Return passed-in <code>null</code> value so that WP will continue to save original post-meta request
    	return $null;
    }
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Custom Field’ is closed to new replies.