前提・実現したいこと
cakephpで開発したサイト内に、記事更新用にwordpressを組み込んでいます。
app/webroot内にwordpressを設置し、cakephpからwordpressのDBを操作しています。
現在、記事一覧・記事ページは表示できていますが、カテゴリーの記事一覧を取得したいです。
記事一覧
https://example.com/blog/
記事ページ
https://example.com/blog/*post_id*/
カテゴリーの記事一覧
https://example.com/blog/category/*category_slug*/
↑ この一覧が表示できません。
- 環境
cakephp3.5.11
wordpress 4.9.8
試したこと
- cakephpのfind時、conditionsで繋いだモデルに対してスラッグを指定しましたがエラー発生。
- cakephpのfind時、containで繋いだモデルに対してconditions(where)を指定しましたが全記事取得されてしまいます。
cakephp
1$conditions = [ 2 'OR' => [ 3 ['post_status' => 'publish'], 4 ['post_status' => 'future'], 5 ], 6 'post_date <=' => date('Y-m-d H:i:s'), 7 'post_type' => 'post', 8 // ↓ 1. のダメだったヤツ。エラー発生。(エラーは下記) 9 //'WpTermRelationships.WpTermTaxonomies.WpTerms' => $slug 10]; 11 12$this->paginate = [ 13 'conditions' => $conditions, 14 'fields' => ['ID', 'post_author', 'post_date', 'post_content', 'post_title'], 15 'order' => ['post_modified' => 'DESC'], 16 'limit' => 20, 17 'contain' => [ 18 'WpPostmetas' => [ 19 'conditions' => [ 20 'meta_key' => '_thumbnail_id' 21 ], 22 'WpPosts.WpPostmetas', 23 ], 24 'WpTermRelationships' => [ 25 'fields' => ['object_id', 'term_taxonomy_id'], 26 'WpTermTaxonomies' => [ 27 'fields' => ['term_taxonomy_id', 'term_id', 'taxonomy'], 28 'conditions' => ['taxonomy' => 'category'], 29 'WpTerms' => [ 30 'fields' => ['term_id', 'name', 'slug'], 31 // ↓ 2. のダメだったヤツ。全記事取得されてしまう。 32 //'conditions' => ['slug' => $slug] 33 ] 34 ], 35 ], 36 ], 37];
1.
1Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'WpTermRelationships.WpTermTaxonomies.WpTerms' in 'where clause'
恐縮ですが、わかる方教えてくださいm(__)m
あなたの回答
tips
プレビュー