0

New to wordpress development, I am working on a plugin that retrieves data from a webservice.

I need an endpoint because the retrieved data also depends on the value of the page's metabox, so in effect the post endpoint variable url is to display a virtual child page.

The desired url would look like this:
example.com/department-a/individuals/smith.john
I need the /(page)/ with /(endpoint)/ and /(variable)

The examples I've seen so far, all point to the use of specifically defined variables after the endpoint. Is it possible to have an endpoint with a query variable after?

2
  • Possible duplicate of Dynamic Endpoints
    – Howdy_McGee
    Feb 19, 2016 at 15:51
  • The Dynamic Endpoints Question/Answer is an interesting approach, however my needs went beyond the use of a defined rewrite : add_rewrite_rule( '^cars/([^/]*)/?$'. Herein lies the advantage of using add_rewrite_endpoint( 'individuals', EP_PAGES ); Feb 19, 2016 at 19:39

1 Answer 1

0

Ok, so it might have been working all along, and I just hadn't flushed the rewrites!

function my_dept_listing_init() {
    //Easy flush
    if (isset($_GET['flush'])) {
        flush_rewrite_rules();
    }

    //endpoint onto which queries are made
    add_rewrite_endpoint( 'individuals', EP_PAGES ); 

    //This filter acts as a controller, inject into content
    add_filter('the_content', 'my_dept_listing_content_ctrl');
}
add_action('init', 'my_dept_listing_init');

function my_dept_listing_content_ctrl($content) {
    global $post;

    $getName = get_query_var('individuals');
    $post->post_title = $getName;
    //Etc
}

Hope this helps someone!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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