Title: Query Tables with
Last modified: August 30, 2016

---

# Query Tables with

 *  Resolved [Bogdan](https://wordpress.org/support/users/bogdanguenther/)
 * (@bogdanguenther)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/query-tables-with/)
 * Hi Tobias,
 * I need to query all TablePress tables and tried this code:
 * $args=array(
    ‘post_type’ => ‘tablepress’, ‘posts_per_page’ => -1, );
 * $table_query=new WP_Query($args);
 * However it does not return any tables. Can you please give me a hint?
 * Thank you,
    Bogdan
 * [https://wordpress.org/plugins/tablepress/](https://wordpress.org/plugins/tablepress/)

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/query-tables-with/#post-6224173)
 * Hi,
 * thanks for your post, and sorry for the trouble.
 * You are using the wrong post type. TablePress uses `tablepress_table`, so that
   your query should be
 *     ```
       $args = array(
         'post_type' => 'tablepress_table',
         'posts_per_page' => -1,
       );
   
       $table_query = new WP_Query( $args );
       ```
   
 * Now, could you elaborate what you are trying to achieve? It’s usually not a good
   idea to directly query tables like this. Instead, it’s better to use e.g.
 *     ```
       $table_ids = TablePress::$model_table->load_all();
       foreach ( $table_ids as $table_id ) {
         $table = TablePress::$model_table->load( $table_id );
         // Do something with $table.
       }
       ```
   
 * Regards,
    Tobias
 *  Thread Starter [Bogdan](https://wordpress.org/support/users/bogdanguenther/)
 * (@bogdanguenther)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/query-tables-with/#post-6224190)
 * Ho Tobias,
 * Thank for for the fast help! I just need to get all TablePress tables in order
   to search for the specific Shortcode and so check where the tables are used.
 * I think for this simple action the directly query is safe to use?
 * Thanks,
    Bogdan
 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/query-tables-with/#post-6224195)
 * Hi,
 * yes, you could then use a query, but the `wp_posts` table does not contain the
   table IDs, which you need for the Shortcodes.
 * I suggest that you take a look at the [posts_search_filter()](https://github.com/TobiasBg/TablePress/blob/master/controllers/controller-frontend.php#L837)
   function in the controller-frontend.php class to see how TablePress searches 
   for Shortcodes.
 * Regards,
    Tobias
 *  Thread Starter [Bogdan](https://wordpress.org/support/users/bogdanguenther/)
 * (@bogdanguenther)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/query-tables-with/#post-6224278)
 * Hi Tobias,
 * > yes, you could then use a query, but the wp_posts table does not
    > contain
   the table IDs, which you need for the Shortcodes.
 * Yes I noticed this fact already myself, I am using the code you suggested now,
   thank you!
 * > I suggest that you take a look at the posts_search_filter() function in the
   controller-
    > frontend.php class to see how TablePress searches for Shortcodes.
 * Thank’s for the tipp, I have a simpler yet more specific attempt.
 * Bogdan
 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/query-tables-with/#post-6224280)
 * Hi,
 * no problem, you are very welcome! 🙂 Good to hear that this helped!
 * Best wishes,
    Tobias

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Query Tables with’ is closed to new replies.

 * ![](https://ps.w.org/tablepress/assets/icon.svg?rev=3192944)
 * [TablePress - Tables in WordPress made easy](https://wordpress.org/plugins/tablepress/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/tablepress/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/tablepress/)
 * [Active Topics](https://wordpress.org/support/plugin/tablepress/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/tablepress/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/tablepress/reviews/)

## Tags

 * [wp_query](https://wordpress.org/support/topic-tag/wp_query/)

 * 5 replies
 * 2 participants
 * Last reply from: [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * Last activity: [11 years, 2 months ago](https://wordpress.org/support/topic/query-tables-with/#post-6224280)
 * Status: resolved