• Super User

    Custom Post Type: modificare lo slug

    Salve a tutti,
    sto utilizzando il theme free [url=http://www.wpexplorer.com/adapt-free-responsive-wordpress-theme/]Adapt theme.

    Vorrei modificare lo SLUG di un Custom Post Type esistente nel theme:

    
    function portfolio_init() {
    
    
    			/**
    			 * Enable the Portfolio custom post type
    			 * http://codex.wordpress.org/Function_Reference/register_post_type
    			 */
    
    
    			$labels = array(
    				'name'					=> __( 'Prodotti', 'wpex' ),
    				'singular_name'			=> __( 'Prodotti Item', 'wpex' ),
    				'add_new'				=> __( 'Aggiungi nuovo prodotto', 'wpex' ),
    				'add_new_item'			=> __( 'Add New Portfolio Item', 'wpex' ),
    				'edit_item'				=> __( 'Modifica prodotto', 'wpex' ),
    				'new_item'				=> __( 'Add New Portfolio Item', 'wpex' ),
    				'view_item'				=> __( 'Vedi Prodotto', 'wpex' ),
    				'search_items'			=> __( 'Search Prodotto', 'wpex' ),
    				'not_found'				=> __( 'No portfolio items found', 'wpex' ),
    				'not_found_in_trash'	=> __( 'No portfolio items found in trash', 'wpex' )
    			);
    			
    			$args = array(
    				'labels'			=> $labels,
    				'public'			=> true,
    				'supports'			=> array( 'title', 'editor', 'excerpt', 'thumbnail', 'comments', 'custom-fields', 'revisions', 'post-formats' ),
    				'capability_type'	=> 'post',
    				'rewrite'			=> array("slug" => "portfolio-item"), // Permalinks format
    				'has_archive'		=> false,
    				'menu_icon'			=> 'dashicons-hammer',
    			); 
    			
    			$args = apply_filters( 'wpex_portfolio_args', $args);
    			
    			register_post_type( 'portfolio', $args );
    
    

    Ho provato a

    1. modificarlo, ma niente
    2. modificarlo, aggiornare i permalink, niente, rimane quello originale

    Suggerimenti?

    Grazie.


  • Moderatore

    Ma questa operazione la stai facendo sul tema originale o su una sua versione child?


  • Super User

    Ciao Stefano,
    la modifica la sto apportando direttamente sul theme originale, anche se è attivo il child.

    Suggerimenti?

    Grazie.


  • Moderatore

    Vedendo il codice è tutto giusto.
    Banalmente; hai provato a disattivare il template e riattivarlo?

    Comunque questa è la funzione completa ( rubata da i codex i wordpress ovviamente )

    
    function codex_book_init() {
    	$labels = array(
    		'name'               => _x( 'Books', 'post type general name', 'your-plugin-textdomain' ),
    		'singular_name'      => _x( 'Book', 'post type singular name', 'your-plugin-textdomain' ),
    		'menu_name'          => _x( 'Books', 'admin menu', 'your-plugin-textdomain' ),
    		'name_admin_bar'     => _x( 'Book', 'add new on admin bar', 'your-plugin-textdomain' ),
    		'add_new'            => _x( 'Add New', 'book', 'your-plugin-textdomain' ),
    		'add_new_item'       => __( 'Add New Book', 'your-plugin-textdomain' ),
    		'new_item'           => __( 'New Book', 'your-plugin-textdomain' ),
    		'edit_item'          => __( 'Edit Book', 'your-plugin-textdomain' ),
    		'view_item'          => __( 'View Book', 'your-plugin-textdomain' ),
    		'all_items'          => __( 'All Books', 'your-plugin-textdomain' ),
    		'search_items'       => __( 'Search Books', 'your-plugin-textdomain' ),
    		'parent_item_colon'  => __( 'Parent Books:', 'your-plugin-textdomain' ),
    		'not_found'          => __( 'No books found.', 'your-plugin-textdomain' ),
    		'not_found_in_trash' => __( 'No books found in Trash.', 'your-plugin-textdomain' )
    	);
    
    	$args = array(
    		'labels'             => $labels,
    		'public'             => true,
    		'publicly_queryable' => true,
    		'show_ui'            => true,
    		'show_in_menu'       => true,
    		'query_var'          => true,
    		'rewrite'            => array( 'slug' => 'book' ),
    		'capability_type'    => 'post',
    		'has_archive'        => true,
    		'hierarchical'       => false,
    		'menu_position'      => null,
    		'supports'           => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' )
    	);
    
    	register_post_type( 'book', $args );
    }
    
    

  • Super User

    No, proverò a disattivarlo ed attivarlo nuovamente, vediamo cosa succede...

    Lato frontend non dovrei modificare nulla, giusto?

    
                                <?php
                                // Setup tax query if needed
                                if ( wpex_get_data('home_port_cat') !== '' && wpex_get_data('home_port_cat') !== 'All' ) {
                                    $wpex_tax_query = array(
                                        array (
                                            'taxonomy'	=> 'portfolio_category',
                                            'field' 	=> 'slug',
                                            'terms'		=> wpex_get_data( 'home_port_cat' )
                                        )
                                    );
                                } else { $wpex_tax_query = NULL; } ?>
                                
                                <?php $wpex_port_query = new WP_Query(
                                    array(
                                        'post_type' => 'portfolio',
                                        'showposts' => wpex_get_data( 'home_port_count', '4' ),
                                        'no_found_rows' => true,
                                        'tax_query' => $wpex_tax_query
                                    )
                                );
                                
                                if( $wpex_port_query->posts ) { ?>
                                    <section id="home-projects" class="clearfix">
                                    	<?php if ( wpex_get_data( 'home_port_heading', '1' ) == '1' ) { ?>
                                			<h2 class="heading"><span><?php echo wpex_get_data('home_port_heading_txt', __( 'Recent Work', 'wpex' ) ); ?></span></h2>
                                    	<?php } ?>
    									<?php $wpex_count=0; ?>
                                        <?php foreach( $wpex_port_query->posts as $post ) : setup_postdata( $post ); ?>
    										<?php $wpex_count++; ?>
                                            <?php get_template_part( 'content', 'portfolio' ); ?>
                                            <?php if( $wpex_count == '4' ) $wpex_count=0; ?>
                                        <?php endforeach; ?>
                                    </section><!-- /home-projects -->
                                <?php } ?>