Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Post featured in home with Wordpress
//Código en el post type:
//Variable Meta para Mobiliario
add_action('admin_init', 'admin_init_ptype');
add_action('save_post', 'save_ptype');
function admin_init_mobiliario(){
add_meta_box("fichadele", "Variables Mobiliario", "meta_options_mobopt", "mobiliario-opticas", 'side', 'high');
}
function meta_options_mobopt(){
global $post;
$custom = get_post_custom($post->ID);
<p><input type="checkbox" name="pic_featured" id="pic_featured" <?=($pic_featured?'checked':'')?> /> <?php _e('Highlight in Home','clmkg');?></p>
}
function save_proyectos(){
global $post;
$fields = array ('porta_ano','porta_idgaleria');
foreach ($fields as $field)
if(isset($_POST[$field]) && $_POST[$field] != "")
update_post_meta($post->ID, $field, $_POST[$field]);
}
En el home:
$attachments = get_posts(
array(
'post_type' => 'pictures',
'orderby' => 'rand',
'posts_per_page' => 7,
'meta_query' => array(
array(
'key' => 'pic_featured',
'value' => 'on'
)
)
)
);
Otra forma
en functions.php
<p><input type="checkbox" name="proy_destacado" id="proy_destacado" <?=($proy_destacado?'checked':'')?> /> Destacar en Inicio</p>
en loop home
$args = array(
'post_type' => 'proyectos’,
'meta_query' => array(
array(
'key' => 'pic_featured',
'value' => 'on'
)
);
$portfolio = new WP_Query($args);
while($portfolio->have_posts()): $portfolio->the_post();
$custom = get_post_custom($portfolio->ID);
$proy_destacado = $custom["proy_destacado"][0];
//loop content
?>
<?php endif; endwhile; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.