- WP-CLI A command line interface for WordPress
- PHPUnit
- Plugin Unit Tests
- Unit Tests for WordPress Plugins – Setting Up Our Testing Suite
Last active
March 17, 2025 11:57
-
-
Save hdknr/5d5dd1a04cb0456c5ef4 to your computer and use it in GitHub Desktop.
WordPress
import sqlite3
# データベースに接続する(例として、wp_database.dbという名前のデータベースファイルを使用)
conn = sqlite3.connect('wp_database.db')
cursor = conn.cursor()
# SQLクエリを実行する
cursor.execute("""
SELECT COUNT(*)
FROM wp_posts
LEFT JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id)
WHERE wp_term_relationships.term_taxonomy_id IN (5);
""")
# 結果を取得する
result = cursor.fetchone()
# 結果を表示する
print(result[0])
# 接続を閉じる
conn.close()
Traceback (most recent call last):
File "<string>", line 8, in <module>
sqlite3.OperationalError: no such table: wp_posts
ご質問のSQLクエリは以下の通りです。
SELECT COUNT(*)
FROM wp_posts
LEFT JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id)
WHERE wp_term_relationships.term_taxonomy_id IN (5);
このSQLクエリを実行することで、カテゴリー5に属する投稿の数を取得できます。
解説:
SELECT COUNT(*)
: 投稿の数を取得します。FROM wp_posts
:wp_posts
テーブルからデータを取得します。LEFT JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id)
:wp_posts
テーブルとwp_term_relationships
テーブルを結合します。wp_posts
テーブルのID
とwp_term_relationships
テーブルのobject_id
が一致するレコードを結合します。WHERE wp_term_relationships.term_taxonomy_id IN (5)
:wp_term_relationships
テーブルのterm_taxonomy_id
が5であるレコードを抽出します。
WP-CLI コマンド
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
cludfront
Cloudfrontで、「error the request could not be satisfied. generated by cloudfront (cloudfront) 」の対応
http://d1fu9ren60wrl1.cloudfront.net/wp-content/uploads/2017/01/f48a676c28403ec3b0d23aa01bf0d711-280x210.jpg だとOK
http://www.fanimal.club/wp-content/uploads/2017/01/f48a676c28403ec3b0d23aa01bf0d711-280x210.jpg だと NG
Alternate Domain Names (CNAMEs)
で設定必要な模様