2
Galera I’m wanting to add a wordpress filter in the posting area :
And I wanted only posts to appear that this function was applied :
function ag_display_custom_meta_box( $post ) {
wp_nonce_field( 'ag_featured_custom_box', 'ag_featured_custom_box_nonce' );
$stored = get_post_meta( $post->ID, '_ag_featured_post', true );
$options = array(
'0' => 'Não usar matéria como destaque',
'principal' => 'Grande',
'secundaria' => 'Pequenos',
'slider' => 'Slider',
'colunaaposentados' => 'Coluna Aposentados',
'colunaunidades' => 'Coluna Unidades',
'colunaeventos' => 'Coluna Eventos',
'colunaesportes' => 'Coluna Esportes',
'colunanoticias' => 'Coluna Noticias',
'colunafenae' => 'Coluna Fenae'
);
$output = "<select name='ag_featured_post_position'>";
foreach ($options as $value => $title):
$output .= "<option ";
if(esc_attr($stored) == $value)
$output .= "selected='selected' ";
$output .= "value='{$value}'>{$title}</option>";
endforeach;
$output .= "</select>";
echo $output;
}
/**
* @param $post_id
*/
function ag_save_meta_box( $post_id ) {
// Validations
$nonce = $_POST['ag_featured_custom_box_nonce'];
if(!isset($_POST['ag_featured_post_position']) || !wp_verify_nonce($nonce, 'ag_featured_custom_box'))
return $post_id;
if(defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE)
return $post_id;
// Check the user's permissions
if ( 'page' == $_POST['post_type'] ) {
if ( ! current_user_can( 'edit_page', $post_id ) ) {
return $post_id;
}
} else {
if ( ! current_user_can( 'edit_post', $post_id ) ) {
return $post_id;
}
}
update_post_meta( $post_id, '_ag_featured_post', sanitize_text_field(
$_POST['ag_featured_post_position']));
}
add_action('save_post', 'ag_save_meta_box');
I read something about add_filter , but I don’t know where to apply and where to put exactly...
The exact use of this filter is : on my site has a 'highlight' area that I use this function to choose what goes and what does not go there... the problem that I have numerous daily posts and are not all that go to the highlight, and the staff responsible for the posts would like to filter only those that are in the highlights... and I don’t know how to do this.
As it is in wordpress the doc I read commented on being in the file Function.php
The function
ag_display_custom_meta_box
returns what type of value? or no return tme– Juven_v
In fact, there is not quite a return, but it shows the selected posts. That wanting or not is a return ... I can be talking shit hahaha
– Axcse
Do you put the whole function? Because generally the wordpress functions, when used as filters, usually return something.
– Juven_v
I added the rest of the function.
– Axcse