Permalink for custom post type

I have created a custom post type called job. Posts are generated with wp_insert_post(), and that works perfectly fine.
My problem is that the permalinks to those posts are either wrong or I have done something wrong myself.
Basicaly the post heads to this url : http://myblog.eu/job/1-adjointe-de-direction-ee/ and it will display only if I go to http://myblog.eu/?job=1-adjointe-de-direction-ee/.

Id like each post to be generated with the right permalink.

Read More

Here is a random post array :

[9] => stdClass Object
        (
            [ID] => 42
            [post_author] => 1
            [post_date] => 2014-03-02 16:40:23
            [post_date_gmt] => 2014-03-02 15:40:23
            [post_content] => [reso_job_post id=8]
            [post_title] => adjoint(e) de direction, La Ciotat
            [post_excerpt] => 
            [post_status] => publish
            [comment_status] => closed
            [ping_status] => open
            [post_password] => 
            [post_name] => 8-adjointe-de-direction-la-ciotat
            [to_ping] => 
            [pinged] => 
            [post_modified] => 2014-03-02 16:40:23
            [post_modified_gmt] => 2014-03-02 15:40:23
            [post_content_filtered] => 
            [post_parent] => 0
            [guid] => http://myblog.eu/job/8-adjointe-de-direction-la-ciotat/
            [menu_order] => 0
            [post_type] => job
            [post_mime_type] => 
            [comment_count] => 0
        )

and here is the code I use to generate posts all variables are set right (as you can see above) :

$new_job_post = array(
                        'post_content' => $job_post_shortcode,
                        'post_title' => $job_post_title,
                        'post_status' => 'publish',
                        'comment_status' => 'closed',
                        'ping_status' => 'open',
                        'post_name' => $job_post_slug,
                        'post_type' => 'job',
                        'comment_count' => '0' 
                        );
                wp_insert_post( $new_job_post );

Here is the code I use to create the custom post type :

function job_custom_init() {
  $labels = array(
    'name'               => 'Jobs',
    'singular_name'      => 'Job',
    'add_new'            => 'Add New',
    'add_new_item'       => 'Add New Book',
    'edit_item'          => 'Edit Job',
    'new_item'           => 'New Job',
    'all_items'          => 'All Jobs',
    'view_item'          => 'View Job',
    'search_items'       => 'Search Jobs',
    'not_found'          => 'No jobs found',
    'not_found_in_trash' => 'No jobs found in Trash',
    'parent_item_colon'  => '',
    'menu_name'          => 'Jobs'
  );

  $args = array(
    'labels'             => $labels,
    'public'             => true,
    'publicly_queryable' => true,
    'show_ui'            => true,
    'show_in_menu'       => true,
    'query_var'          => true,
    'rewrite'            => array( 'slug' => 'job' ),
    'capability_type'    => 'post',
    'has_archive'        => true,
    'hierarchical'       => false,
    'menu_position'      => 5,
    'supports'           => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt' ),
    'taxonomies'         => array( 'category', 'post_tag' )
  );

  register_post_type( 'job', $args );
}
add_action( 'init', 'job_custom_init' );
function my_rewrite_flush() {
    job_custom_init();
    flush_rewrite_rules();
}
register_activation_hook( __FILE__, 'my_rewrite_flush' );

Thank you.

Related posts

Leave a Reply

1 comment