• I am building a plugin which allows admins to add staff members to a database. I have created a function in my plugin class file…

    cp_libstaff_frontend_display()

    …which displays a table of every staff member in the database to front-end users. This function is attached to shortcode which displays at the URL:

    mysite.com/librarywp/staff-directory

    Now what I would like to do is have a link on each staff member’s name which takes the user to a page for just that staff member’s information. For example,

    mysite.com/librarywp/libstaff/1

    Where ‘1’ is the ID of the staff member whose individual page should be retrieved. I have created an endpoint for this like so:

    public static function cp_libstaff_add_rewrites(){
     add_rewrite_endpoint( 'libstaff', EP_PERMALINK );
    }
    
    public static function cp_libstaff_filter_request( $vars ){
      if( !isset( $vars['libstaff'] ) ) $vars['libstaff'] = true;
      return $vars;
    }
    
    public static function cp_libstaff_rewrite_catch_libstaff(){
      if( get_query_var( 'libstaff' ) ){
    
          echo 'WHAT NOW?';
          exit();
      }
    }
    
    add_action( 'init', array('Libstaff', 'cp_libstaff_add_rewrites') );
    add_action( 'template_redirect', array('Libstaff', 'cp_libstaff_rewrite_catch_libstaff') );
    add_filter( 'request', array('Libstaff', 'cp_libstaff_filter_request') );

    After this point I am beyond confused about how to proceed with the callback function. Should there be a custom post type created in here somewhere? A template of some sort?

  • The topic ‘Endpoint Callback Display for Custom Plugin’ is closed to new replies.