Hello all,
I've this problem, when editing a custom post type Yoast data change on website and custom type list of wordpress but not in the edit page.
WordPress version: 3.4.2
WordPress SEO version: 1.3.4.1
my code for custom post-type:
<?php
/*
Plugin Name: Ricette
Description: Plugin per la gestione delle ricette
Version: 1.0
Author: Mauro Accornero
Author URI: http://www.mauroaccornero.it/
*/
add_action( 'init', 'create_ricette' );
function create_ricette() {
register_post_type( 'ricette',
array(
'labels' => array(
'name' => 'Ricette',
'singular_name' => 'Ricette',
'add_new' => 'Aggiungi Nuova',
'add_new_item' => 'Aggiungi Nuova Ricetta',
'edit' => 'Modifica',
'edit_item' => 'Modifica Ricetta',
'new_item' => 'Nuova Ricetta',
'view' => 'Visualizza',
'view_item' => 'Visualizza Ricetta',
'search_items' => 'Cerca Ricetta',
'not_found' => 'Nessuna Ricetta trovata',
'not_found_in_trash' =>
'Nessun Ricetta trovata nel cestino',
'parent' => 'Padre Ricetta'
),
'public' => true,
'publicly_queryable' => true,
'menu_position' => 15,
'supports' =>
array( 'title','editor','thumbnail','excerpt' ),
'taxonomies' => array(/*'ingredienti',*/'portate','filtri'),
'menu_icon' =>
plugins_url( 'images/image.png', __FILE__ ),
'has_archive' => true
)
);
$labels_portate = array(
'name' => _x( 'Portate', 'taxonomy general name' ),
'singular_name' => _x( 'Portata', 'taxonomy singular name' ),
'search_items' => __('Search Portate') ,
'all_items' => __('Tutte le Portate') ,
'parent_item' => __('Portata Genitore') ,
'parent_item_colon' => __('Portata Genitore:') ,
'edit_item' => __('Modifica Portata') ,
'update_item' => __('Aggiorna Portata') ,
'add_new_item' => __('Aggiungi nuova Portata') ,
'new_item_name' => __('Nome nuova Portata') ,
'menu_name' => __('Portate'),
'separate_items_with_commas' => __('Separa i nomi delle portate con una virgola'),
'choose_from_most_used' => __('Scegli tra le portate più utilizzate')
);
register_taxonomy('portate',array('ricette'), array(
'labels' => $labels_portate,
'show_ui' => true,
'rewrite' => array( 'slug' => 'portate' )
));
/*portate order field*/
// Add term page
function pippin_taxonomy_add_new_meta_field() {
// this will add the custom meta field to the add new term page
echo "<div class='form-field'>
<label for='term_meta[custom_term_meta]'>Ordine portata</label>
<input type='text' name='term_meta[custom_term_meta]' id='term_meta[custom_term_meta]' value=''>
</div>";
}
add_action( 'portate_add_form_fields', 'pippin_taxonomy_add_new_meta_field', 10, 2 );
// Edit term page
function pippin_taxonomy_edit_meta_field($term) {
// put the term ID into a variable
$t_id = $term->term_id;
// retrieve the existing value(s) for this meta field. This returns an array
$term_meta = get_option( "taxonomy_$t_id" ); ?>
<tr class="form-field">
<th scope="row" valign="top"><label for="term_meta[custom_term_meta]">Ordine portata</label></th>
<td>
<input type="text" name="term_meta[custom_term_meta]" id="term_meta[custom_term_meta]" value="<?php echo esc_attr( $term_meta['custom_term_meta'] ) ? esc_attr( $term_meta['custom_term_meta'] ) : ''; ?>">
<p class="description"><?php _e( 'Enter a value for this field','pippin' ); ?></p>
</td>
</tr>
<?php
}
add_action( 'portate_edit_form_fields', 'pippin_taxonomy_edit_meta_field', 10, 2 );
// Save extra taxonomy fields callback function.
function save_taxonomy_custom_meta( $term_id ) {
if ( isset( $_POST['term_meta'] ) ) {
$t_id = $term_id;
$term_meta = get_option( "taxonomy_$t_id" );
$cat_keys = array_keys( $_POST['term_meta'] );
foreach ( $cat_keys as $key ) {
if ( isset ( $_POST['term_meta'][$key] ) ) {
$term_meta[$key] = $_POST['term_meta'][$key];
}
}
// Save the option array.
update_option( "taxonomy_$t_id", $term_meta );
}
}
add_action( 'edited_portate', 'save_taxonomy_custom_meta', 10, 2 );
add_action( 'create_portate', 'save_taxonomy_custom_meta', 10, 2 );
/*portate order field*/
$labels_ingredienti = array(
'name' => _x('Ingredienti', 'taxonomy general name' ) ,
'singular_name' => _x('Ingrediente', 'taxonomy singular name' ),
'search_items' => __('Search Ingrediente' ),
'all_items' => __('Tutte le Ingrediente' ),
'parent_item' => __('Ingrediente Genitore') ,
'parent_item_colon' => __('Ingrediente Genitore:') ,
'edit_item' => __('Modifica Ingrediente') ,
'update_item' => __('Aggiorna Ingrediente' ),
'add_new_item' => __('Aggiungi nuovo Ingrediente' ),
'new_item_name' => __('Nome nuovo Ingrediente' ),
'menu_name' => __('Ingredienti'),
'separate_items_with_commas' => __('Separa i nomi degli ingredienti con una virgola'),
'choose_from_most_used' => __('Scegli tra gli ingredienti più utilizzati')
);
register_taxonomy('ingredienti',array('ingredienti_piatti'), array(
'labels' => $labels_ingredienti,
'show_ui' => true,
'rewrite' => array( 'slug' => 'ingredienti' )
));
$labels_filtro = array(
'name' => _x('Filtri', 'taxonomy general name' ) ,
'singular_name' => _x('Filtro', 'taxonomy singular name' ),
'search_items' => __('Cerca Filtro' ),
'all_items' => __('Tutti i filtri' ),
'parent_item' => __('Filtro Genitore') ,
'parent_item_colon' => __('Filtro Genitore:') ,
'edit_item' => __('Modifica Filtro') ,
'update_item' => __('Aggiorna Filtro' ),
'add_new_item' => __('Aggiungi nuovo Filtro' ),
'new_item_name' => __('Nome nuovo Filtro' ),
'menu_name' => __('Filtri') ,
'separate_items_with_commas' => __('Separa i nomi dei filtri con una virgola'),
'choose_from_most_used' => __('Scegli tra i filtri più utilizzate')
);
register_taxonomy('filtri',array('ricette'), array(
'labels' => $labels_filtro,
'show_ui' => true,
'rewrite' => array( 'slug' => 'filtri' )
));
}
add_action( 'add_meta_boxes', 'meta_ricette_related_add' );
function meta_ricette_related_add()
{
add_meta_box( 'related-item', 'Contenuti Relazionati', 'meta_ricette_related_output', 'ricette', 'normal', 'high' );
}
function meta_ricette_related_output( $post )
{
$values = get_post_custom( $post->ID );
$first_related_recipe = isset( $values['first_related_recipe'] ) ? esc_attr( $values['first_related_recipe'][0] ) : '';
$second_related_recipe = isset( $values['second_related_recipe'] ) ? esc_attr( $values['second_related_recipe'][0] ) : '';
$related_product = isset( $values['related_product'] ) ? esc_attr( $values['related_product'][0] ) : '';
wp_nonce_field( 'my_meta_box_nonce', 'meta_box_nonce' );
?>
<p>
<label for="related_product">Prodotto relazionato</label>
<?php
$args = array(
'post_type' => 'prodotti',
'nopaging' => true
);
$query = new WP_Query( $args );
echo '<select name="related_product" id="related_product"><option value="">Seleziona un Prodotto</option>';
while ( $query->have_posts() ) : $query->the_post();
echo '<option value="'.get_the_ID().'" '.selected( $related_product, get_the_ID() ).'>';
the_title();
echo '</option>';
endwhile;
echo '</select>';
?>
</p>
<p>
<label for="first_related_recipe">Prima ricetta relazionata</label>
<?php
$args = array(
'post_type' => 'ricette',
'nopaging' => true
);
$query = new WP_Query( $args );
echo '<select name="first_related_recipe" id="first_related_recipe"><option value="">Seleziona una Ricetta</option>';
while ( $query->have_posts() ) : $query->the_post();
echo '<option value="'.get_the_ID().'" '.selected( $first_related_recipe, get_the_ID() ).'>';
the_title();
echo '</option>';
endwhile;
echo '</select>';
?>
</p>
<p>
<label for="second_related_recipe">Seconda ricetta relazionata</label>
<?php
$args = array(
'post_type' => 'ricette',
'nopaging' => true
);
$query = new WP_Query( $args );
echo '<select name="second_related_recipe" id="second_related_recipe"><option value="">Seleziona una Ricetta</option>';
while ( $query->have_posts() ) : $query->the_post();
echo '<option value="'.get_the_ID().'" '.selected( $second_related_recipe, get_the_ID() ).'>';
the_title();
echo '</option>';
endwhile;
echo '</select>';
?>
</p>
<?php
}
add_action( 'save_post', 'save_ricette_related_meta' );
function save_ricette_related_meta( $post_id )
{
// Bail if we're doing an auto save
if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
// if our nonce isn't there, or we can't verify it, bail
if( !isset( $_POST['meta_box_nonce'] ) || !wp_verify_nonce( $_POST['meta_box_nonce'], 'my_meta_box_nonce' ) ) return;
// if our current user can't edit this post, bail
if( !current_user_can( 'edit_post' ) ) return;
if( isset( $_POST['first_related_recipe'] ) )
update_post_meta( $post_id, 'first_related_recipe', esc_attr( $_POST['first_related_recipe'] ) );
if( isset( $_POST['second_related_recipe'] ) )
update_post_meta( $post_id, 'second_related_recipe', esc_attr( $_POST['second_related_recipe'] ) );
if( isset( $_POST['related_product'] ) )
update_post_meta( $post_id, 'related_product', esc_attr( $_POST['related_product'] ) );
}
add_filter( 'template_include',
'include_template_function', 1 );
function include_template_function( $template_path ) {
if ( get_post_type() == 'ricette' ) {
if ( is_single() ) {
// checks if the file exists in the theme first,
// otherwise serve the file from the plugin
if ( $theme_file = locate_template( array
( 'single-ricette.php' ) ) ) {
$template_path = $theme_file;
} else {
$template_path = plugin_dir_path( __FILE__ ) .
'/single-ricette.php';
}
}
}
return $template_path;
}
?>
maybe the problem is in my code...