• Resolved redstormj

    (@redstormj)


    I’m nearly done with my website and I am fine tunning some things. I could almost swear that at some point I saw an option to change the default post type from “listings” to something else, but for the love of God I can’t seem to find that anywhere now so I don’t know if I was just dreaming when I saw that.

    Could you confirm or clarify if it is possible to change the post type name to something other than “listings”? In my case I need this because my website is in a different language.

    Thanks!

    https://www.ads-software.com/plugins/wpcasa/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author WPSight

    (@wpsight)

    Hi redstormj,

    You can find the corresponding code here: https://github.com/wpsight/wpcasa/blob/master/wpcasa/includes/class-wpsight-post-types.php#L266

    With the following code you could change the labels to your needs:

    /**
     * Change listing post type labels
     */
    add_filter( 'wpsight_post_type_labels_listing', 'my_post_type_labels_listing' );
    
    function my_post_type_labels_listing( $labels ) {
    
    	// Set post type labels
    
    	$labels = array(
    	    'name' 			 => _x( 'Listings', 'listing', 'wpcasa' ),
    	    'singular_name' 	 => _x( 'Listing', 'listing', 'wpcasa' ),
    	    'add_new' 		 => _x( 'Add New', 'listing', 'wpcasa' ),
    	    'add_new_item' 	 => _x( 'Add New Listing', 'listing', 'wpcasa' ),
    	    'edit_item' 		 => _x( 'Edit Listing', 'listing', 'wpcasa' ),
    	    'new_item' 		 => _x( 'New Listing', 'listing', 'wpcasa' ),
    	    'view_item' 		 => _x( 'View Listing', 'listing', 'wpcasa' ),
    	    'search_items' 	 => _x( 'Search Listings', 'listing', 'wpcasa' ),
    	    'not_found' 		 => _x( 'No listings found', 'listing', 'wpcasa' ),
    	    'not_found_in_trash' => _x( 'No listings found in Trash', 'listing', 'wpcasa' ),
    	    'menu_name' 	 => _x( 'Listings', 'listing', 'wpcasa' ),
    	);
    
    	return $labels;
    
    }

    Best regards,
    Simon [WPCasa]

    Thread Starter redstormj

    (@redstormj)

    Ha! I knew I had seen that somewhere!

    Thanks buddy.

    Thread Starter redstormj

    (@redstormj)

    Actually, this isn’t working. I must be missing something simple somewhere.

    I am using:

    /**
     * Change listing post type labels
     */
    add_filter( 'wpsight_post_type_labels_listing', 'my_post_type_labels_listing' );
    
    function my_post_type_labels_listing( $labels ) {
    
    	// Set post type labels
    
    	$labels = array(
    	    'name' 			 => _x( 'Propiedades', 'propiedades', 'wpcasa' ),
    	    'singular_name' 	 => _x( 'Propiedad', 'propiedad', 'wpcasa' ),
    	    'add_new' 		 => _x( 'Agregar Nueva', 'propiedad', 'wpcasa' ),
    	    'add_new_item' 	 => _x( 'Agregar Nueva Propiedad', 'propiedad', 'wpcasa' ),
    	    'edit_item' 		 => _x( 'Editar Propiedad', 'propiedad', 'wpcasa' ),
    	    'new_item' 		 => _x( 'Nueva Propiedad', 'propiedad', 'wpcasa' ),
    	    'view_item' 		 => _x( 'Ver Propiedad', 'propiedad', 'wpcasa' ),
    	    'search_items' 	 => _x( 'Buscar Propiedades', 'propiedades', 'wpcasa' ),
    	    'not_found' 		 => _x( 'No se encontraron propiedades', 'propiedades', 'wpcasa' ),
    	    'not_found_in_trash' => _x( 'No se encontraron propiedades en el basurero', 'propiedades', 'wpcasa' ),
    	    'menu_name' 	 => _x( 'Propiedades', 'propiedades', 'wpcasa' ),
    	);
    
    	return $labels;
    
    }

    I can see labels changing so I am sure the code is working, but this is having no impact on the actual post type name (the url). So all properties are being listed under:

    https://mywebsite.com/listing/property-name

    I am hoping to change “listing” in the url for something different like:

    https://mywebsite.com/propiedades/property-name

    Hopefully that makes sense.

    Thanks!

    Plugin Author WPSight

    (@wpsight)

    The given code was indeed just for the labels. If you want to change the slug, you need to apply another filter:

    /**
     * Custom listing slug
     */
    add_filter( 'wpsight_rewrite_listings_slug', 'my_rewrite_listings_slug' );
    
    function my_rewrite_listings_slug( $slug ) {
    
    	$slug = 'propiedades';
    
    	return $slug;
    
    }

    After adding this code you will have to save your permalinks on WP-Admin > Settings > Permalinks to update the rewrite rules.

    Regarding the labels… if you just want to translate, I recommend to work with plugin translations. Spanish is included. We use the term anuncio but you can easily change that to your needs using Loco Translate in your WordPress admin or Poedit as a desktop tool.

    Hope this helps.

    Thread Starter redstormj

    (@redstormj)

    Massive thanks! this is much appreciated. Works as expected.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Post Type name changeable?’ is closed to new replies.