Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Mike Jolley

    (@mikejolley)

    We don’t use featured images in the plugin; we only upload a company logo.

    You can use this however https://gist.github.com/mikejolley/e8094a1e78e939d0d746

    Thread Starter IanPW

    (@ianpw)

    Great! Thank you for that. What file does that need to be added to?

    Plugin Author Mike Jolley

    (@mikejolley)

    Functions.php of your theme.

    My theme contains support for featured image and gallery. I found following in my theme

    add_action( 'job_manager_update_job_data', array( $this, 'save_featured_image' ), 10, 2 );
    add_action( 'job_manager_update_job_data', array( $this, 'save_gallery_images' ), 10, 2 );

    and using debugger, I found that these are called, but the following functions contained in same file never get called, thus even though the images are uploaded and attached to listing, they aren’t set as featured/listing gallery images.

    public function save_featured_image( $job_id, $values ) {
    	$attachment_url = $values[ 'job' ][ 'featured_image' ];
    	$attach_id = listify_get_attachment_id_by_url( $attachment_url );
    
    	if ( $attach_id != get_post_thumbnail_id( $job_id ) ) {
    		set_post_thumbnail( $job_id, $attach_id );
    	} elseif( '' == $attachment_url && has_post_thumbnail( $job_id ) ) {
    		delete_post_thumbnail( $job_id );
    	}
    }
    
    public function save_gallery_images( $job_id, $values ) {
    	$images = $values[ 'job' ][ 'gallery_images' ];
    
    	if ( ! isset( $images ) || empty( $images ) ) {
    		return;
    	}
    
    	$gallery = array();
    
    	foreach ( $images as $image ) {
    		$gallery[] = listify_get_attachment_id_by_url( $image );
    	}
    
    	$gallery = implode( ',', $gallery );
    
    	$shortcode = '[gallery ids=' . $gallery . ']';
    
    	update_post_meta( $job_id, '_gallery', $shortcode );
    }

    Edit: Nevermind, the function listify_get_attachment_id_by_url doesn’t seem to be working. Looks like I need to debug it myself or contact Astoundify.

    I currently have applied this quick dirty fix in listify_get_attachment_id_by_url() in Listify 1.0.5.

    $prefix = '/uploads/';
    $prefix_length = strlen($prefix);
    
    $match = substr($parsed_url[1], $prefix_length);
    $attachment = $wpdb->get_col( $wpdb->prepare( "SELECT post_id FROM {$wpdb->prefix}postmeta WHERE meta_key = '_wp_attached_file' AND meta_value RLIKE %s;", $match ) );
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Featured Image on Job Post’ is closed to new replies.