I am trying to create links like the ones in the post tab (see image below).
I created my WP_List_table
but I am not sure how to create those links or how to get them to show a different db query.
I know about the extra_tablenav
function in the class but this adds things after the bulk action area, so this doesn’t seem to do what I want.
As mentioned in the comments, if this is an existing table you wish to add/remove links from, see this answer.
If this a custom subclass of
WP_List_Table
, e.g.:Then you add these links by overriding the
get_views()
method. This should return an array:array ( id => link )
. This should link back to the page, attaching some value to a query variable (which I’ll callcustomvar
).When constructing the links, check for the current value for
customvar
and conditionally add the classcurrent
to highlight in bold the current view.So (inside) your class.
Then in your
prepare_items
method you can retrieve thecustomvar
method and alter your query according to it’s value.Note: The links can be used to perform actions. I would store the ‘action’ value in the query variable
action
(remember to use nonces!). Then hook ontoload-{$hook}
(see Codex), check permissions and nonces, and then perform the action.If you are going to include ‘action links’, make sure you use nonces – and you should only display the link for users with the necessary capabilities.
You have to call
views();
when rendering the page content.Put
<?php $wp_list_table->views(); ?>
after page title and before the form.
For this problem i have created a custom style , you can follow