• Resolved EricB50

    (@ericb50)


    I have a plugin with 2 tabs. Each tab displays a different instance of wp_list_tables. However the screen options declared like this:

    $arguments = array(
    ‘label’ => __(‘Stalls Per Page’, $this->plugin_text_domain),
    ‘default’ => 50,
    ‘option’ => ‘stalls_per_page’
    );

    add_screen_option(‘per_page’, $arguments);

    Only picks up the last table configuration loaded. Is there a way to get the screen options to change based on which table html table data tab is open? Or am I doing something wrong with how I’m managing the instances for 2 tables?

    • This topic was modified 3 years, 9 months ago by EricB50.
Viewing 6 replies - 1 through 6 (of 6 total)
  • Moderator bcworkz

    (@bcworkz)

    It looks like the list tables were never intended to be tabbed. I think you’d need to modify the query for the first table to use the value saved that’s only applied to the second. If this is a posts list table, use the “pre_get_posts” action and set the “posts_per_page” arg accordingly. The challenge will be having code that differentiates this table query from all other posts queries. There ought to be some distinctive query vars set that will let you do this.

    Thread Starter EricB50

    (@ericb50)

    Thanks for the help. Yes I can set some tab query vars, but it’s not clear to me how to get the screen options to only examine one table dataset. It seems to be pulling data from whatever table instance was most recently accessed. Is there a way to specify to the screen options which instance to use?

    It’s a bit of a mystery to me how the screen options interface with the wp_list_table object.

    Moderator bcworkz

    (@bcworkz)

    The items per page count is stored in the current screen’s WP_Screen object’s options property, keyed 'edit_' . $post_type . '_per_page'. Use the object’s get_option() method. The value is stored in the current user’s meta data under the same key.

    Thread Starter EricB50

    (@ericb50)

    Ok thanks. I’ve been looking at this object using get_current_screen.

    It seems to be ignoring what I’ve set. For example when I look at the current screen:

    _options:WP_Screen:private] => Array
    (
    [per_page] => Array
    (
    [label] => Stalls Per Page
    [default] => 50
    [option] => stalls_per_page
    )
    )

    However this does not appear to have any impact on the Screen Options as it is populated with column names and item counts and per_page settings that do not match what is shown in the object. It does show the Pagination for Stalls and set at 50 but it does not seem to be carried into the wp_list_table as 20 are shown per page.

    Anyway that could be related to something else. Is there an acceptable way to define screens based on tabs? Is that a valid approach or should I just change from tabs to pages?

    Thanks again for all your help.

    Moderator bcworkz

    (@bcworkz)

    It may be you’re altering the value too late (or too early) to affect the current screen. And its not persisting between requests. I tried changing the meta value in the DB and it was reflected in the next request. Note that if the value is still the default, there is no stored meta value. It’s only set on change.

    It may not fit your need, but I’m sure if you saved the user meta value in the DB, it’ll be applied to the next screen request.

    Incidentally, you could override the set value on the current request by altering the respective posts query’s “posts_per_page” query var through the “pre_get_posts” action.

    Thread Starter EricB50

    (@ericb50)

    Thanks. I’ll experiment with some of those suggestions to see what works.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Two instances of wp_list_table and tabs how to configure Screen Options separate’ is closed to new replies.