前提・実現したいこと
WORDPRESSの投稿ページでの記事一覧表示(関連投稿の表示)で、
「投稿のカスタムフィールドの値」と「ユーザーのカスタムフィールドの値(Advanced Custom Fieldsで設定したもの)」で絞り込んで表示したいのですが、うまくできず、ヒントなどあれば教えていただきたいです。
現状、配列の結合によるエラーがでます。
$myPosts = var_dump($item_args + $users_args);
を
$myPosts = $item_args ;
にすれば、ユーザーカスタムフィールド以外での絞り込みはできました。
発生している問題・エラーメッセージ
array(5) { [0]=> object(WP_Post)#6797 (24) { ["ID"]=> int(280) ["post_author"]=> string(1) "2" ["post_date"]=> string(19) "2019-03-24 22:56:20" ["post_date_gmt"]=> string(19) "2019-03-24 13:56:20" ["post_content"]=> string(0) "" ["post_title"]=> string(27) "改登録サンプル商品" ["post_excerpt"]=> string(0) "" ["post_status"]=> string(7) "publish" ["comment_status"]=> string(6) "closed" ["ping_status"]=> string(6) "closed" ["post_password"]=> string(0) "" ["post_name"]=> string(81) "%e6%94%b9%e7%99%bb%e9%8c%b2%e3%82%b5%e3%83%b3%e3%83%97%e3%83%ab%e5%95%86%e5%93%81" ["to_ping"]=> string(0) "" ["pinged"]=> string(0) "" ["post_modified"]=> string(19) "2019-03-24 22:56:20" ["post_modified_gmt"]=> string(19) "2019-03-24 13:56:20" ["post_content_filtered"]=> string(0) "" ["post_parent"]=> int(0) ["guid"]=> string(57) "https://leather-makers.com/?post_type=products&p=280" ["menu_order"]=> int(0) ["post_type"]=> string(8) "products" ["post_mime_type"]=> string(0) "" ["comment_count"]=> string(1) "0" ["filter"]=> string(3) "raw" } [1]=> object(WP_Post)#7170 (24) { ["ID"]=> int(267) ["post_author"]=> string(1) "2" ["post_date"]=> string(19) "2019-03-23 18:42:02" ["post_date_gmt"]=> string(19) "2019-03-23 09:42:02" ["post_content"]=> string(0) "" ["post_title"]=> string(60) "テストユーザーのブラウンなサンプルの商品" ["post_excerpt"]=> string(0) "" ["post_status"]=> string(7) "publish" ["comment_status"]=> string(6) "closed" ["ping_status"]=> string(6) "closed" ["post_password"]=> string(0) "" ["post_name"]=> string(198) "%e3%83%86%e3%82%b9%e3%83%88%e3%83%a6%e3%83%bc%e3%82%b6%e3%83%bc%e3%81%ae%e3%83%94%e3%83%b3%e3%82%ad%e3%83%bc%e3%83%91%e3%82%b9%e3%82%b1%e3%83%bc%e3%82%b9%e7%9a%84%e3%81%aa%e3%82%b5%e3%83%b3%e3%83%97" ["to_ping"]=> string(0) "" ["pinged"]=> string(0) "" ["post_modified"]=> string(19) "2019-03-24 22:39:00" ["post_modified_gmt"]=> string(19) "2019-03-24 13:39:00" ["post_content_filtered"]=> string(0) "" ["post_parent"]=> int(0) ["guid"]=> string(57) "https://leather-makers.com/?post_type=products&p=267" ["menu_order"]=> int(0) ["post_type"]=> string(8) "products" ["post_mime_type"]=> string(0) "" ["comment_count"]=> string(1) "0" ["filter"]=> string(3) "raw" } [2]=> object(WP_Post)#7169 (24) { ["ID"]=> int(278) ["post_author"]=> string(1) "2" ["post_date"]=> string(19) "2019-03-24 22:47:09" ["post_date_gmt"]=> string(19) "2019-03-24 13:47:09" ["post_content"]=> string(0) "" ["post_title"]=> string(57) "テストユーザーのカテゴリー長財布の商品" ["post_excerpt"]=> string(0) "" ["post_status"]=> string(7) "publish" ["comment_status"]=> string(6) "closed" ["ping_status"]=> string(6) "closed" ["post_password"]=> string(0) "" ["post_name"]=> string(171) "%e3%83%86%e3%82%b9%e3%83%88%e3%83%a6%e3%83%bc%e3%82%b6%e3%83%bc%e3%81%ae%e3%82%ab%e3%83%86%e3%82%b4%e3%83%aa%e3%83%bc%e9%95%b7%e8%b2%a1%e5%b8%83%e3%81%ae%e5%95%86%e5%93%81" ["to_ping"]=> string(0) "" ["pinged"]=> string(0) "" ["post_modified"]=> string(19) "2019-03-24 23:26:53" ["post_modified_gmt"]=> string(19) "2019-03-24 14:26:53" ["post_content_filtered"]=> string(0) "" ["post_parent"]=> int(0) ["guid"]=> string(57) "https://leather-makers.com/?post_type=products&p=278" ["menu_order"]=> int(0) ["post_type"]=> string(8) "products" ["post_mime_type"]=> string(0) "" ["comment_count"]=> string(1) "0" ["filter"]=> string(3) "raw" } [3]=> object(WP_Post)#6917 (24) { ["ID"]=> int(271) ["post_author"]=> string(1) "2" ["post_date"]=> string(19) "2019-03-24 22:42:59" ["post_date_gmt"]=> string(19) "2019-03-24 13:42:59" ["post_content"]=> string(0) "" ["post_title"]=> string(63) "テストユーザーのピンクピンクサンプルの商品" ["post_excerpt"]=> string(0) "" ["post_status"]=> string(7) "publish" ["comment_status"]=> string(6) "closed" ["ping_status"]=> string(6) "closed" ["post_password"]=> string(0) "" ["post_name"]=> string(189) "%e3%83%86%e3%82%b9%e3%83%88%e3%83%a6%e3%83%bc%e3%82%b6%e3%83%bc%e3%81%ae%e3%83%94%e3%83%b3%e3%82%af%e3%83%94%e3%83%b3%e3%82%af%e3%82%b5%e3%83%b3%e3%83%97%e3%83%ab%e3%81%ae%e5%95%86%e5%93%81" ["to_ping"]=> string(0) "" ["pinged"]=> string(0) "" ["post_modified"]=> string(19) "2019-03-24 22:42:59" ["post_modified_gmt"]=> string(19) "2019-03-24 13:42:59" ["post_content_filtered"]=> string(0) "" ["post_parent"]=> int(0) ["guid"]=> string(57) "https://leather-makers.com/?post_type=products&p=271" ["menu_order"]=> int(0) ["post_type"]=> string(8) "products" ["post_mime_type"]=> string(0) "" ["comment_count"]=> string(1) "0" ["filter"]=> string(3) "raw" } [4]=> object(WP_Post)#6916 (24) { ["ID"]=> int(273) ["post_author"]=> string(1) "2" ["post_date"]=> string(19) "2019-03-24 22:44:39" ["post_date_gmt"]=> string(19) "2019-03-24 13:44:39" ["post_content"]=> string(0) "" ["post_title"]=> string(69) "テストユーザーのイエローモンキーサンプルの商品" ["post_excerpt"]=> string(0) "" ["post_status"]=> string(7) "publish" ["comment_status"]=> string(6) "closed" ["ping_status"]=> string(6) "closed" ["post_password"]=> string(0) "" ["post_name"]=> string(198) "%e3%83%86%e3%82%b9%e3%83%88%e3%83%a6%e3%83%bc%e3%82%b6%e3%83%bc%e3%81%ae%e3%82%a4%e3%82%a8%e3%83%ad%e3%83%bc%e3%83%a2%e3%83%b3%e3%82%ad%e3%83%bc%e3%82%b5%e3%83%b3%e3%83%97%e3%83%ab%e3%81%ae%e5%95%86" ["to_ping"]=> string(0) "" ["pinged"]=> string(0) "" ["post_modified"]=> string(19) "2019-03-24 22:44:39" ["post_modified_gmt"]=> string(19) "2019-03-24 13:44:39" ["post_content_filtered"]=> string(0) "" ["post_parent"]=> int(0) ["guid"]=> string(57) "https://leather-makers.com/?post_type=products&p=273" ["menu_order"]=> int(0) ["post_type"]=> string(8) "products" ["post_mime_type"]=> string(0) "" ["comment_count"]=> string(1) "0" ["filter"]=> string(3) "raw" } }
該当のソースコード
php
1global $post; 2 3$args = array( 4'numberposts' => 5, //表示件数 5'post_type' => 'products', //カスタム投稿タイプ名 6'author__not_in' => array( $author_id ), //表示作成者を除外 7'orderby' => 'rand',//ランダム表示 8); 9$item_args = get_posts($args); 10 11$users = array( 12'meta_query' => array( array( 13'key' => '関連商品の表示', //ユーザーカスタムフィールドのキー 14'value' => '利用する', //ユーザーカスタムフィールドの値 15'compare' => 'LIKE', 16 17) ), 18); 19$users_args = get_users( $users ); 20 21$myPosts = var_dump($item_args + $users_args); 22 23if($myPosts) : 24foreach($myPosts as $post) : setup_postdata($post); 25 26//ループ表示部分 27 28endforeach; 29endif; 30wp_reset_postdata();
試したこと
ここに問題に対して試したことを記載してください。
補足情報(FW/ツールのバージョンなど)
ここにより詳細な情報を記載してください。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/03/27 10:07
2019/03/27 10:22
2019/03/29 02:38
2019/03/29 02:52
2019/03/29 02:54