I have a custom post type define below and I want to add a custom row action to allow me to 'update' the post via the admin panel

class LeagueCpt
    function __construct()
        add_action( 'init', array(&$this,'registerLeagueCPT'));
        add_filter('post_row_actions', array(&$this,'post_row_actions'), 0, 2);

    function registerLeagueCPT()
        $leagueLabels = array(
            'name' => _x( 'Leagues', 'league' ),
            'singular_name' => _x( 'League', 'league' ),
            'add_new' => _x( 'Add New', 'league' ),
            'add_new_item' => _x( 'Add New League', 'league' ),
            'edit_item' => _x( 'Edit League', 'league' ),
            'new_item' => _x( 'New League', 'league' ),
            'view_item' => _x( 'View League', 'league' ),
            'search_items' => _x( 'Search Leagues', 'league' ),
            'not_found' => _x( 'No league found', 'league' ),
            'not_found_in_trash' => _x( 'No leagues found in Trash', 'league' ),
            'parent_item_colon' => _x( 'Parent League:', 'league' ),
            'menu_name' => _x( 'Leagues', 'league' ),

        $leagueArgs = array(
            'labels' => $leagueLabels,
            'hierarchical' => false,
            'description' => 'League Details',
            'supports' => array( 'title','editor','excerpt','thumbnail','custom-fields','page-attributes','comments'),
            'public' => true,
            'show_ui' => true,
            'show_in_menu' => true,
            'show_in_nav_menus' => true,
            'publicly_queryable' => true,
            'exclude_from_search' => false,
            'has_archive' => true,
            'query_var' => true,
            'can_export' => true,
            'rewrite' => true,
            'capability_type' => 'post'
        register_post_type('league', $leagueArgs );

This is the code that registers the row action

function post_row_actions($actions, $post) {
    $actions = array_merge($actions, array(
        'update' => sprintf('<a href="%s">Update</a>',
    return $actions;

I've defined a function update() in the same php file, in which i plan to do real work

function update()
    // do some custom update stuff on the post content

My problem is how can I ensure that the URL request with the update action calls the function above?

I've used the following resources

Custom Post Row Actions


Row actions for custom post types?



2 Answers 2


You'd have to use the $_GET method. Here, I'm hooking in admin_head-{$pagenow}, depending on your functionality maybe you'll need to hook in load-{$pagenow}.

Prefix your var names to not colide with any WordPress internals, in this case my-update for the action name:


Sample code:

add_action( 'admin_head-edit.php', 'custom_get_http_wpse_82761' );

function custom_get_http_wpse_82761()
    global $typenow;
    if( 'league' != $typenow )

    if( isset( $_GET['my-update'] ) )
        // do stuff

I came across this post on how-do-i-best-handle-custom-plugin-page-actions which i found very useful since the action is mapped directly to a function via the wordpress 'admin_action' hook. The only problem it only supports html forms which send a POST request. I want to keep the URL's link that 'post_row_actions' allow me.

My wordaround is to use jQuery to convert the GET request details of the URL into a POST request. I added an 'id' attribute to the href and added the following JQuery code. It takes the original URL and then makes a POST request.

jQuery(document).ready( function() {
    jQuery("a#bhaa_league_populate").bind("click", function(event) {
        var url = jQuery(this).attr("href");

        var p = url.split('?');
        var action = p[0];
        var params = p[1];

        jQuery.post( action, params);

It allows me the best of both worlds.

Your Answer

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

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