• Resolved strawberry_juice

    (@strawberry_juice)


    Hi, I would need some help with WordPress and custom post types/ permalinks.

    I registered custom post type by the name “services” with the following arguments:

    $args = array(
    	'labels' => $labels,
    	'singular_label' => __('services'),
    	'public' => true,
    	'query_var' => true,
    	'show_ui' => true,
    	'menu_icon' => get_stylesheet_directory_uri() . '/img/wp-menu-ico.png',
    	'menu_position' => null,
    	'capability_type' => 'page',
    	'hierarchical' => false,
    	'rewrite' => array( 'slug' => 'services', 'with_front' => true ),
    	'supports' => array('title', 'editor', 'thumbnail', 'page-attributes' )
    );

    Then I created new custom post/service by the title of “Make up” and slug “make-up”. When I try to preview this post from WP dashboard using the Preview link it gives me 404. I can’t query this post from outside the dashboard too.

    Now I found that when I use the following url structure it shows me the post: /?post_type=services&p=243

    This however doesn’t work: /?services=make-up

    Checked my mysql table and the post by id of 243, post_name “make-up” and post_type “services” exists.

    What I’m trying to do is to use pretty urls with custom post type, which doesn’t work. I disabled the pretty permalinks in WP options and still doesn’t work.

    Any ideas what am I doing wrong?

Viewing 4 replies - 1 through 4 (of 4 total)
  • You need to save your permalinks after adding or modifying any post types registered using register_post_type ..

    NOTE: Try one of the provided permalink structures, and additionally confirm regular posts work when using permalinks.

    Thread Starter strawberry_juice

    (@strawberry_juice)

    thank You!

    the problem is i did save permalinks a few times and they work for my pages/subpages (in parent/child url structure), posts, custom post types (in general), custom taxonomies. they just don’t work for one particular custom post type.

    i can query posts of this particular type using WP_Query or query_posts but when i click on a link generated with the_permalink() i get 404 code.

    Thread Starter strawberry_juice

    (@strawberry_juice)

    Thanks once again Mark! My problem was using the same slug for custom taxonomy and custom post type rewrite and query_var value.

    Certainly a taxonomy and post type using the same named query var will cause problems.

    Glad to hear you found the source of your problem, and happy i could help.. ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘can't query custom post type by post_name (slug)’ is closed to new replies.