3

I am trying to add multiple endpoints in one url like:

http://localhost:1000/manage-lead/lead_id/1000/product_id/123455

But this way the query var lead_id is equal to 1000/product/123455 and not 1000.

When I do it the following way everything goes right:

http://localhost:1000/manage-lead/lead_id/1000/?product_id=123455

So I think that I need to add some rewrite rules, so Wordpress understands that lead_id and product_id are 2 query vars.

How I add my endpoints:

function add_lead_management_endpoints() {

    add_rewrite_endpoint( 'lead_id', EP_PAGES );
    add_rewrite_endpoint( 'product_id', EP_PAGES );

}
add_action( 'init', 'add_lead_management_endpoints' );
2

Not sure of the context for this, is it a custom post type or just a page?

This might be something which you're looking for -

function add_lead_management_endpoints() {
    add_rewrite_rule(
        'manage-lead/lead_id/([0-9]{1,})/product_id/([0-9]{1,})',
        'index.php?pagename=manage-lead&lead_id=$matches[1]&product_id=$matches[2]',
        'top'
    );

    add_rewrite_tag( '%lead_id%', '([^&]+)' );
    add_rewrite_tag( '%product_id%', '([^&]+)' );
}
add_action( 'init', 'add_lead_management_endpoints' );

You'll need to flush permalinks for this to take affect (visit settings->permalinks).

  • Did this resolve your problem @Robbert? – Elliott Apr 14 '16 at 20:49
  • It did not test i yet, but you asked whether it is a page or post type and I answered page. So does this change anything in your code? – Robbert Apr 15 '16 at 9:29
  • The above is setup to work with the page manage-lead – Elliott Apr 15 '16 at 11:53

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.