0

i create new post type and the slug can be changed from backend ex:

register_post_type( 'job', array(
    'rewrite' => array(
        'slug' => $slug
    );
));

$slug is variable that i take from backend. and its working fine if im doing normal request. i get right URL using get_permalink function.

but the problem arise when i doing ajax request. i dive into the code, and i get normal request and ajax request return different result of permastruck.

on normal request, its return right result of permastruck for example :

[job] => Array
    (
        [with_front] => 1
        [ep_mask] => 1
        [paged] => 1
        [feed] => 
        [forcomments] => 
        [walk_dirs] => 1
        [endpoints] => 1
        [struct] => /lowongan-kerja/%job%
    )

and the URL result look like this : http://localhost/lowongan-kerja/programmer/

but on ajax, its returning different permastruck :

[job] => Array
    (
        [with_front] => 1
        [ep_mask] => 1
        [paged] => 1
        [feed] => 
        [forcomments] => 
        [walk_dirs] => 1
        [endpoints] => 1
        [struct] => /job/%job%
    )

and very weird, the URL look like this : http://localhost/job/programmer/

how can i make both on normal & ajax request having the same URL?

  • do you register your post type on the init action? – Milo Dec 12 '15 at 5:23
  • Yes i do. add_action('init', array(&$this, 'register_post_type')); – Jeg Bagus Dec 12 '15 at 5:25
  • without seeing your code in its entirety it's difficult to say what the issue may be. this is certainly not normal behavior, and should work without having to add an additional permastruct. – Milo Dec 12 '15 at 5:57
0

So i examine several plugin to learn how it work and find solution by using add_permastruct

add_permastruct( 'job', '/' . $slug . '/%job%', array(
            'with_front'  => false,
            'ep_mask'     => EP_NONE,
            'paged'       => false,
            'feed'        => false,
            'forcomments' => false,
            'walk_dirs'   => true,
            'endpoints'   => false,
        ));

and the problem is solved :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.