4.0Essential Grid 4.0 is here — see what’s new

FAQ

Assign Native Post Data to a Skin Element

Essential Grid 3 · The 4.0 FAQ

Grab information already available in your posts. And then assign it data to a skin element using the following PHP.

Step 1:

Edit/Add an element inside the Item Skin Editor, wrapping the post data attribute in percentage characters.

Step 2:

Add the following code to your theme’s “functions.php” file.

add_filter('essgrid_post_meta_handle', 'eg_add_post_option');
add_filter('essgrid_post_meta_content', 'eg_add_post_content', 10, 4);

function eg_add_post_option($post_options){

// where 'author_id' is the attribute of the data to pull in
$post_options['author_id'] = array('name' => 'Author ID');

return $post_options;

}

function eg_add_post_content($meta_value, $meta, $post_id, $post){

// where 'author_id' is the attribute of the data to pull in
if($meta === 'author_id'){

$post_author_id = get_post_field( 'post_author', $post_id );

// return the post data value, and wrap it in any HTML you want
return '<div class="author-id">Author ID = '.$post_author_id.'</div>';

}

return $meta_value;

}