Database Interactions with WP_Query and $wpdb
summary
Shows how to use the global $wpdb methods like get_var, get_row, get_col, get_results and the prepare method to safely run SQL, plus properties (num_rows, rows_affected, insert_id) and table prefix usage. Demonstrates WP_Query loops that must call wp_reset_query or wp_reset_postdata to restore the global post object, builds a WP_Query for the ten most recent posts, and a meta_query filtering for 15 posts with a featured image via meta_query '_thumbnail_id'. Covers when to use get_posts or $wpdb instead of WP_Query.
AI-written summary · about
chapters (29)
- 0:00Intro
- 0:25Jonathan Daggerhart
- 1:12What is a database?
- 1:47Let's build our own database table!
- 2:13Simple Form Submissions Table
- 4:12What is $wpdb?
- 6:45$wpdb SELECT Methods
- 7:43SELECT example: get_row()
- 8:29SELECT example: get_results()
- 9:46Dynamic Data: Always prepare()
- 12:03One more prepare() for the road
- 12:25Other $wpdb Methods
- 13:42Important $wpdb properties
- 15:40Using the prefix property
- 16:14Using the core table names
- 16:45$wpdb - Questions?
- 19:50WP_Query() & global $wp_query
- 20:43Why use WP_Query()
- 21:56Exploring the Main Loop
- 22:38These two loops are equivalent
- 24:28Implications of replacing the global $post object
- 25:44Enter wp_reset_query()
- 26:20Complete WP_Query() Loop
- 27:03Simple WP_Query() arguments
- 28:07Other arguments
- 29:49Ex1: Working WP_Query() and Loop
- 30:36Ex1: SQL generated by WP_Query()
- 33:42query_posts() & get_posts()
- 37:19WP_Query() Questions?
