• Hi,

    I’m having problems getting my post to list a custom_post_type (apartment). When reading the apartment single post I get this permalink structure:

    https://www.blog.com/apartments/my-apartment-title

    But when I change the url to:

    https://www.blog.com/apartments/

    It gives me error 404.

    On the post registration I use this code

    function register_apartments ()
    	{
    		# Register post type apartment
    		register_post_type
    		(
    			'apartment',
    			array
    			(
    				'_builtin'            => false,
    				'labels'              => array
    				(
    					'name'               => _x( 'Apartments', 'post type general name', MYSITE_ADMIN_TEXTDOMAIN ),
    					'singular_name'      => _x( 'Apartment', 'post type singular name', MYSITE_ADMIN_TEXTDOMAIN ),
    					'add_new'            => _x( 'Add New', 'apartment', MYSITE_ADMIN_TEXTDOMAIN ),
    					'add_new_item'       => __( 'Add New Apartment', MYSITE_ADMIN_TEXTDOMAIN ),
    					'edit_item'          => __( 'Edit Apartment', MYSITE_ADMIN_TEXTDOMAIN ),
    					'new_item'           => __( 'New Apartment', MYSITE_ADMIN_TEXTDOMAIN ),
    					'view_item'          => __( 'View Apartment', MYSITE_ADMIN_TEXTDOMAIN ),
    					'search_items'       => __( 'Search Apartments', MYSITE_ADMIN_TEXTDOMAIN ),
    					'not_found'          => __( 'No apartments found', MYSITE_ADMIN_TEXTDOMAIN ),
    					'not_found_in_trash' => __( 'No apartments found in Trash', MYSITE_ADMIN_TEXTDOMAIN ),
    					'parent_item_colon'  => ''
    				),
    				'description'         => __( 'Apartment description' ),
    				'singular_label'      => __( 'Apartment', MYSITE_ADMIN_TEXTDOMAIN ),
    				'capability_type'     => 'delete_published_posts',
    				'menu_position'       => 3,
    				'exclude_from_search' => false,
    				'capability_type'     => 'post',
    				'hierarchical'        => false,
    				'public'              => true,
        			'publicly_queryable'  => true,
    				'show_ui'             => true,
    				'ep_mask' => 1,
    				'rewrite'             => array ( 'slug' => 'apartments', 'with_front' => false ),
    				'query_var'           => true,
    				'taxonomies'          => array ( 'category' ),
    				'supports'            => array ( 'title', 'editor', 'thumbnail', 'revisions' )//, 'excerpt', 'comments', 'custom-fields' )
    			)
    		);
    }
    add_action ( 'init', 'register_post_type'  );

    Any help would be appreciated.
    Thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter Peter Monte

    (@stevestall)

    By doing a print_r on global $wp_query I could analyse what is being requested ($wp_query->request) on database:

    SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts WHERE 1=1 AND 0 = 1 AND wp_posts.post_type IN ('apartment', 'news') AND (wp_posts.post_status = 'publish' OR wp_posts.post_author = 1 AND wp_posts.post_status = 'private') GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0, 12

    I notice that a specific call for my custom_post_types is being requested. which is good. What I don’t understand is why it is searching for ‘news’ post_type when the query-slug ‘apartments’ is applied to custom_post_type “apartment”.

    Another point is on the WHERE statement were there is an AND 0 = 1. By changing this line to AND 1=1 or simply deleting it and making again that call with $wpdb->get_results I get all apartments and news ID`s listed.

    Any help would be appreciated.
    Thanks

    Can any of you help me with the issue I’ve been having with permalinks?

    https://www.ads-software.com/support/topic/permalink-trouble-with-iis-rewrite?replies=1

    Thread Starter Peter Monte

    (@stevestall)

    Sorry alisyme, I don’t think I have the skills to help you.

    Thread Starter Peter Monte

    (@stevestall)

    Unfortunately a solution for this requires know-how higher than I can provide. Fortunately there are people who have what it needs to get things going:

    https://www.ads-software.com/extend/plugins/simple-custom-post-type-archives/

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to list Custom Post Type on permalink’ is closed to new replies.