Article 54PG3 [SOLVED] WordPress internals - finding table linking wp_terms and wp_posts

[SOLVED] WordPress internals - finding table linking wp_terms and wp_posts

by
Turbocapitalist
from LinuxQuestions.org on (#54PG3)
I've been trying to extract records that have been assigned specific terms from a WordPress database. The terms are in the table wp_terms and the rest of the record is in wp_posts. However, I am unable to find which third table has the necessary fields to join those two first tables so that I may search for wp_posts by the assigned terms.

Which table would have references to both wp_posts and wp_terms by their respective IDs?

Code:MariaDB [database]> show tables;
+-----------------------------+
| Tables_in_database |
+-----------------------------+
| wp_commentmeta |
| wp_comments |
| wp_crossreferences |
| wp_gdsr_data_article |
| wp_gdsr_data_category |
| wp_gdsr_data_comment |
| wp_gdsr_data_multi |
| wp_gdsr_ips |
| wp_gdsr_moderate |
| wp_gdsr_multis |
| wp_gdsr_multis_data |
| wp_gdsr_multis_trend |
| wp_gdsr_multis_values |
| wp_gdsr_templates |
| wp_gdsr_votes_log |
| wp_gdsr_votes_trend |
| wp_links |
| wp_options |
| wp_pollsa |
| wp_pollsip |
| wp_pollsq |
| wp_postmeta |
| wp_posts |
| wp_redirection_groups |
| wp_redirection_items |
| wp_redirection_logs |
| wp_redirection_modules |
| wp_relevanssi |
| wp_relevanssi_cache |
| wp_relevanssi_excerpt_cache |
| wp_relevanssi_log |
| wp_relevanssi_stopwords |
| wp_search_phrases |
| wp_sph_counter |
| wp_sph_stats |
| wp_term_relationships |
| wp_term_taxonomy |
| wp_terms |
| wp_usermeta |
| wp_users |
| wp_wp2pdf |
| wp_wp2pdf_fonts |
+-----------------------------+
42 rows in set (0.001 sec)Below is the wp_terms table:

Code:MariaDB [database]> show columns from wp_terms;
+------------+---------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+---------------------+------+-----+---------+----------------+
| term_id | bigint(20) unsigned | NO | PRI | NULL | auto_increment |
| name | varchar(200) | NO | MUL | | |
| slug | varchar(200) | NO | UNI | | |
| term_group | bigint(10) | NO | | 0 | |
+------------+---------------------+------+-----+---------+----------------+
4 rows in set (0.001 sec)And here is the structure of the wp_posts table:

Code:MariaDB [database]> show columns from wp_posts;
+-----------------------+---------------------+------+-----+---------------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------------------+---------------------+------+-----+---------------------+----------------+
| ID | bigint(20) unsigned | NO | PRI | NULL | auto_increment |
| post_author | bigint(20) unsigned | NO | MUL | 0 | |
| post_date | datetime | NO | | 0000-00-00 00:00:00 | |
| post_date_gmt | datetime | NO | | 0000-00-00 00:00:00 | |
| post_content | longtext | NO | | NULL | |
| post_title | text | NO | | NULL | |
| post_category | int(4) | NO | | 0 | |
| post_excerpt | text | NO | | NULL | |
| post_status | varchar(20) | NO | MUL | publish | |
| comment_status | varchar(20) | NO | | open | |
| ping_status | varchar(20) | NO | | open | |
| post_password | varchar(20) | NO | | | |
| post_name | varchar(200) | NO | MUL | | |
| to_ping | text | NO | | NULL | |
| pinged | text | NO | | NULL | |
| post_modified | datetime | NO | | 0000-00-00 00:00:00 | |
| post_modified_gmt | datetime | NO | | 0000-00-00 00:00:00 | |
| post_content_filtered | longtext | NO | | NULL | |
| post_parent | bigint(20) unsigned | NO | MUL | 0 | |
| guid | varchar(255) | NO | | | |
| menu_order | int(11) | NO | | 0 | |
| post_type | varchar(20) | NO | MUL | post | |
| post_mime_type | varchar(100) | NO | | | |
| comment_count | bigint(20) | NO | | 0 | |
+-----------------------+---------------------+------+-----+---------------------+----------------+
24 rows in set (0.002 sec)I've looked at quite a few of the tables but the apparent inconsistency in the naming is causing the solution to escape me for now.latest?d=yIl2AUoC8zA latest?i=YmTaJ-Oio1k:pRkXs3Z0jQ4:F7zBnMy latest?i=YmTaJ-Oio1k:pRkXs3Z0jQ4:V_sGLiP latest?d=qj6IDK7rITs latest?i=YmTaJ-Oio1k:pRkXs3Z0jQ4:gIN9vFwYmTaJ-Oio1k
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments