0

I've created a custom page in my wp-admin panel to show my custom model in a grid. It extends wp_list_table, and the grid works great with sorting and pagination. I'm having trouble adding an "Add New" button above the grid, however. I've added the button:

<a href="admin.php?page=certificates&amp;action=new" class="add-new-h2">Add New</a>

And it takes me to the same page, with the action=new in the request, as expected. I'm not quite sure how to proceed from there, however. I'd like the page to display a form that lets the user add a new item when the URL contains that action, and otherwise display the grid. I tried adding a URL check to my process_bulk_action() function, as this is already looking for various actions in the URL, but it doesn't seem to call that function when clicking the "add new" button.

Does anyone have any advice on this, or a link to a guide which includes the add new button? All I've found are guides on removing that button, but that's not helpful when I haven't been able to get the button working in the first place.

2
  • Do you want to use native post editor at all? If you just want a custom page then it's up to you how precisely to implement it, hard to say without seeing how the rest is set up.
    – Rarst
    Commented Aug 17, 2016 at 17:49
  • I guess native post editor is what I'm looking for. Does this allow me to create a custom post type and custom fields, and then automate the process of displaying, editing, creating, and deleting the custom post type? Commented Aug 17, 2016 at 17:53

1 Answer 1

1

As per comments you likely you want to use native editor rather than build one from scratch.

From poking through the core source outputting the link for that would be along the lines of:

$post_new_file = "post-new.php?post_type=$post_type"

if ( isset( $post_new_file ) && current_user_can( $post_type_object->cap->create_posts ) )
    echo ' <a href="' . esc_url( admin_url( $post_new_file ) ) . '" class="page-title-action">' . esc_html( $post_type_object->labels->add_new ) . '</a>';

Editor links for existing posts are easier with dedicated get_edit_post_link() function for them.

Having that you can customize editor experience via your CPT registration (you can declare if you want title, editor, and so on) and by adding additional metabox to it (there are a lot of solutions for that around).

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.