2017-07-07 10 views
1

では動作しません:Wordpressのhave_posts()私は私のfunctions.phpでカスタムポストタイプを作成したループ

add_action('init', 'create_post_type'); 
function create_post_type() { 
    register_post_type( 
     'specialities', 
     array(
      'labels' => array( 
       'name' => __('Besonderheiten'), 
       'singular_name' => __('Besonderheit') 
      ), 
      'public' => true, 
      'has_archive' => true, 
      'supports' => array('title', 'editor', 'thumbnail') 
     ) 
    ); 
} 

は、それから私は、WP-adminのセクションでは、いくつかの記事を追加しました。

私はすべての記事照会:$クエリは、私は全体のことをvar_dumped空でないことを確認するために

$args = query_posts(array(
     'post_type' => 'specialities', 
     'posts_per_page' => -1 
    )); 
$query = new WP_Query($args); 

を - >それは空ではありません。 var_dumpはすべての投稿を表示しました。 ...なぜ私はdiv要素(スライドショーclearfix)しかし、誰の子のdiv(名物のclearfixを)見ることができるウェブインスペクタで

<?php if(!empty($query)){ ?> 
    <div class="slideshow clearfix"> 
     <?php while ($query->have_posts()) : $query->the_post(); ?> 
      <div class="specialities clearfix"><?php echo the_title(); ?></div> 
     <?php endwhile; ?> 
    </div> 
<?php } ?> 

???:

は、だから私はループにこのクエリを試してみました

オブジェクト(WP_Query)#6956(48){[ "クエリ"] =>アレイ(5){[0] =>オブジェクト(WP_Post)#6961:場合にそう

は、ここでのvar_dumpです(1) "1" ["post_date"] =>文字列(19) "2017-07-07 21:03: 191 "[" post_date_gmt "] =>文字列(19)" 2017-07-07 19:03:19 "[" post_content "] =>文字列(591)" Lorem ipsum dolor sit amet、consetetur sadipscing elitr、sed diam nonumy彼らは祈りの祈りを捧げて、祈りの祈りを捧げて、祈りの祈りを捧げた。宇宙飛行士エリート、宇宙飛行士、宇宙飛行士マグカップはマグマの一種であり、マグマはマグマの一種です。卒業生と卒業生は、卒業後も卒業しています。 "[" post_itatus "] =>文字列(8)" Beispiel "[" post_excerpt "] =>文字列(0)" "[" post_status "] = > "文字列(0)" "文字列(6)" "文字列" "post_modified"] => string(19) "" "post_name"] => string(8) "beispiel" ["to_ping"] =>文字列(0) "" ["pinged"] =>文字列(0) "2017-07-07 21:03:42" ["post_modified_gmt"] =>文字列(19) "2017-07-07 19:03:42" ["post_content_filtered"] =>文字列(0) "" [" ["post_parent"] => string(12) "specialties" ["post_parent"] => int(0)["guid"] =>文字列(57) "" ["menu_order"] => int "[" filter "] => string(3)" raw "} [1] =>オブジェクト(WP_Post)#6923 (1) "1" ["post_date"] =>文字列(19) "2017-07-07 21:01: "" "post_content"] =>文字列(591) "Lorem ipsum dolor sit ame" ["post_date_gmt"] =>文字列(19) "2017-07-07 19:01:06"宇宙飛行士、宇宙飛行士、宇宙飛行士、宇宙飛行士、宇宙飛行士、宇宙飛行士、宇宙飛行士、宇宙飛行士、卒業生と卒業生は、卒業後も卒業しています。 Stet clita kasd gubergren、海の傷跡はありません。Lorem ipsum dolor sit amet。 Lorem ipsum dolle sitet、consetetur sadipscing elitr、sidipscing elitr、sidipscing elitr、sidipscingエリート、sidipscingエリート、sidipscingエリート、sidipscingエリート、エイミードエリート、エリート、エイリアンエリート、卒業生と卒業生は、卒業後も卒業しています。 Stet clita kasd gubergren、海の傷跡はありません。Lorem ipsum dolor sit amet。"" ["post_status"] => string(7) "公開" ["comment_status"] =>文字列(8) "[" post_excerpt "] =>文字列(0) "post_password"] =>文字列(0) "" ["post_name"] =>文字列(8) "spaetzle" ["to_ping" "" ["post_modified"] =>文字列(19) "2017-07-07 21:01:06" ["post_modified_gmt"] =>文字列(0) "" ["pinged"] =>文字列(0) (0)["guid"] =>文字列(19) "2017-07-07 19:01:06" ["post_content_filtered"] =>文字列(0) "" ["post_parent"] => int ["post_mime_type"] =>文字列(0) "" ["comment_count"] = "文字列(57)" "[" menu_order "] => int(0)[" post_type " > [文字列]> [文字列](3) "未加工"} [2] =>オブジェクト(WP_Post)#6960(24){["ID"] => int(55) "post_date"] =>文字列(19) "2017-07-07 21:00:11" ["post_date_gmt"] => string(19) "post_author"] =>文字列(1) "1" 07-07 19:00:11 "[" post_content "] =>文字列(591)" Lorem ipsum dolor sit amet、consetetur sadipscing elitr、sed diam nonumy eirmod tempor invidunt ut labore e magna aliquyam erat、sed diam voluptuaなどがあります。卒業生と卒業生は、卒業後も卒業しています。 Stet clita kasd gubergren、海の傷跡はありません。Lorem ipsum dolor sit amet。 Lorem ipsum dolle sitet、consetetur sadipscing elitr、sidipscing elitr、sidipscing elitr、sidipscingエリート、sidipscingエリート、sidipscingエリート、sidipscingエリート、エイミードエリート、エリート、エイリアンエリート、卒業生と卒業生は、卒業後も卒業しています。 "パスタポモドーロ" ["post_excerpt"] =>文字列(0) "" ["post_status"] ["post_title"] =>ストリングclita kasd gubergren、 ["post_password"] =>文字列(0) ""文字列(7) "公開" ["comment_status"] =>文字列(6) "閉じた" ["ping_status"] => ["post_modified"] =>文字列(0) "" ping "" = "文字列(0)" " (19) "2017-07-07 21:00:11" ["post_modified_gmt"] =>文字列(19) "2017-07-07 19:00:11" ["post_content_filtered"] =>文字列(0) " "" post_parent "] => string(12)" specialties "[" post_parent "] => int(0)[" guid "] =>文字列(57)" "[" menu_order "] => int (3) "raw"} [3] =>オブジェクト(WP_Post(1)); "[" post_mime_type "] =>文字列(0)" "[" comment_count " (1) "1" ["post_date"] =>文字列(19) "2017-07-07 20 :57:49 "[" post_date_gmt "] =>文字列(19)" 2017-07-07 18:57:49 "[" post_content "] =>文字列(591)" Lorem ipsumお金を払って、お金を稼ぐことはできません。卒業生と卒業生は、卒業後も卒業しています。 Stet clita kasd gubergren、海の傷跡はありません。Lorem ipsum dolor sit amet。 Lorem ipsum dolle sitet、consetetur sadipscing elitr、sidipscing elitr、sidipscing elitr、sidipscingエリート、sidipscingエリート、sidipscingエリート、sidipscingエリート、エイミードエリート、エリート、エイリアンエリート、卒業生と卒業生は、卒業後も卒業しています。 "[" post_title "] =>"パスタトマトモッツァレッラ "[" post_excerpt "] =>ストリング(0)" "[" post_status "ストリングclita kasd gubergren、海のタキマタsanctus est Lorem ipsum dolor sit amet。 ["post_password"] =>文字列(0) "" ping_status "] =>文字列(7)"公開 "[" comment_status "] =>文字列(6) "" ["post_modified"] =>文字列(0) "" ["post_name"] =>文字列(2) "53" ["to_ping"] =>文字列(0) 19 ")" 2017-07-07 20:59:08 "[" post_modified_gmt "] =>文字列(19)" 2017-07-07 18:59:08 "[" post_content_filtered "] =>文字列(0)" " ["post_parent"] => string(12) "specialties" ["post_parent"] => int(0)["guid"] =>文字列(57) "" ["menu_order"] => int "post_mime_type"] =>ストリング(0) "" ["comment_count"] =>ストリング(1) "0" ["フィルター"] =>ストリング(3) "未加工"} [4] =>オブジェクト(WP_Post) "post_date"] =>文字列(19) "2017-07-07 20:1" [post_author "] =>文字列(1)" 1 "[" post_date "] => int(51) "" post_content "] =>文字列(591)" Lorem ipsum do "、" ["post_date_gmt"] =>文字列(19) "2017-07-07 18:56:44"それは、あなたの恋人と一緒に過ごすことができます。卒業生と卒業生は、卒業後も卒業しています。 Stet clita kasd gubergren、海の傷跡はありません。Lorem ipsum dolor sit amet。 Lorem ipsum dolle sitet、consetetur sadipscing elitr、sidipscing elitr、sidipscing elitr、sidipscingエリート、sidipscingエリート、sidipscingエリート、sidipscingエリート、エイミードエリート、エリート、エイリアンエリート、卒業生と卒業生は、卒業後も卒業しています。 Stet clita kasd gubergren、海の傷跡はありません。Lorem ipsum dolor sit amet。"" ["post_status"] => string(7) "publish" ["comment_status"] =>文字列(9) "ハンバーガー" ["post_excerpt"] =>文字列(0) ["post_password"] =>文字列(0) "" ["post_name"] =>文字列(9) "hamburger" ["to_ping" "" ["post_modified"] =>文字列(19) "2017-07-07 20:56:44" ["post_modified_gmt"] =>文字列(0) "" ["pinged"] =>文字列(0) (0)["guid"] =>文字列(19) "2017-07-07 18:56:44" ["post_content_filtered"] =>文字列(0) "" ["post_parent"] => int ["post_mime_type"] =>文字列(0) "" ["comment_count"] = "文字列(57)" "[" menu_order "] => int(0)[" post_type " "オブジェクト"(WP_Post)#6961(24) "["] "" ["フィルタ"] =>文字列(3) "未加工"}} ["query_vars"] =>配列(69) "1" ["post_date"] =>文字列(19) "2017-07-07 21:03:19" ["post_date"] => int(59)["post_author" "post_date_gmt"] =>文字列(19) "2017-07-07 19:03:19" ["post_content"] =>文字列(591) "Lorem ipsum dolor sit amet、consetetur sadipscing elitr、sed diam nonumy e黙っていた時に、あなたは夢中になりました。卒業生と卒業生は、卒業後も卒業しています。 Stet clita kasd gubergren、海の傷跡はありません。Lorem ipsum dolor sit amet。 Lorem ipsum dolle sitet、consetetur sadipscing elitr、sidipscing elitr、sidipscing elitr、sidipscingエリート、sidipscingエリート、sidipscingエリート、sidipscingエリート、エイミードエリート、エリート、エイリアンエリート、卒業生と卒業生は、卒業後も卒業しています。 "[" post_itatus "] =>文字列(8)" Beispiel "[" post_excerpt "] =>文字列(0)" "[" post_status "] = > "文字列(0)" "文字列(6)" "文字列" "post_modified"] => string(19) "" "post_name"] => string(8) "beispiel" ["to_ping"] =>文字列(0) "" ["pinged"] =>文字列(0) "2017-07-07 21:03:42" ["post_modified_gmt"] =>文字列(19) "2017-07-07 19:03:42" ["post_content_filtered"] =>文字列(0) "" [" ["post_parent"] => string(12) "specialties" ["post_parent"] => int(0)["guid"] =>文字列(57) "" ["menu_order"] => int "[" filter "] => string(3)" raw "} [1] =>オブジェクト(WP_Post)#6923 (1) "1" ["post_date"] =>文字列(19) "2017-07-07 21:01: "" "post_content"] =>文字列(591) "Lorem ipsum dolor sit ame" ["post_date_gmt"] =>文字列(19) "2017-07-07 19:01:06"宇宙飛行士、宇宙飛行士、宇宙飛行士、宇宙飛行士、宇宙飛行士、宇宙飛行士、宇宙飛行士、宇宙飛行士、卒業生と卒業生は、卒業後も卒業しています。 Stet clita kasd gubergren、海の傷跡はありません。Lorem ipsum dolor sit amet。 Lorem ipsum dolle sitet、consetetur sadipscing elitr、sidipscing elitr、sidipscing elitr、sidipscingエリート、sidipscingエリート、sidipscingエリート、sidipscingエリート、エイミードエリート、エリート、エイリアンエリート、卒業生と卒業生は、卒業後も卒業しています。 "[" post_itatus "] =>文字列(8)" Spaetzle "[" post_excerpt "] =>文字列(0)" "[" post_status "] = > "文字列(0)" "文字列(6)" "文字列" "post_modified"] => string(19) "post_modified"] =>文字列(0) "2017-07-07 21:01:06" ["post_modified_gmt"] =>文字列(19) "2017-07-07 19:01:06" ["post_content_filtered"] =>文字列(0) "" [" ["post_parent"] => string(12) "specialties" ["post_parent"] => int(0)["guid"] =>文字列(57) "" ["menu_order"] => int "" "" "raw"} [2] =>オブジェクト(WP_Post)#6960( "0" (1) "1" ["post_date"] =>文字列(19) "2017-07-07 21:00: 11 "[" post_date_gmt "] =>文字列(19)" 2017-07-07 19:00:11 "[" post_content "] =>文字列(591)" Lorem ipsum dolor sit ame宇宙飛行士、宇宙飛行士、宇宙飛行士、宇宙飛行士、宇宙飛行士、宇宙飛行士、宇宙飛行士、宇宙飛行士、卒業生と卒業生は、卒業後も卒業しています。 Stet clita kasd gubergren、海の傷跡はありません。Lorem ipsum dolor sit amet。 Lorem ipsum dolle sitet、consetetur sadipscing elitr、sidipscing elitr、sidipscing elitr、sidipscingエリート、sidipscingエリート、sidipscingエリート、sidipscingエリート、エイミードエリート、エリート、エイリアンエリート、卒業生と卒業生は、卒業後も卒業しています。 Stet clita kasd gubergren、海の傷跡はありません。Lorem ipsum dolor sit amet。"" "post_status"] => string(7) "publish" ["comment_status"] => "パスタポモドーロ" ["post_excerpt"] =>ストリング(0) ["post_password"] =>文字列(0) "" ["post_name"] =>文字列(14) "パスタポモドーロ" ["post_modified"] =>文字列(19) "2017-07-07 21:00:11" [["to_ping"] =>文字列(0) "" ["pinged"] =>文字列(0) "post_modified_gmt"] => string(19) "2017-07-07 19:00:11" ["post_content_filtered"] =>文字列(0) "" ["post_parent"] => int(0)["guid" ["post_mime_type"] =>文字列(0) "" ["comment_count"]> = "文字列(0) "[ID"] => int( ")"> = "文字列(3) (19)2017-07-07 20:57:49 "[" post_date_gmt "] =>文字列(19)[" post_author "] =>文字列(1)" 1 "[" post_date "] =>文字列(19) "2017-07-07 18:57:49" ["post_content"] =>文字列(591) "Lorem ipsum dolor sit amet、consetetur sadipscing elitr、sed diam nonumy eirmod tempor invidu宇宙開発事業団と大統領令、宗教団体、卒業生と卒業生は、卒業後も卒業しています。 Stet clita kasd gubergren、海の傷跡はありません。Lorem ipsum dolor sit amet。 Lorem ipsum dolle sitet、consetetur sadipscing elitr、sidipscing elitr、sidipscing elitr、sidipscingエリート、sidipscingエリート、sidipscingエリート、sidipscingエリート、エイミードエリート、エリート、エイリアンエリート、卒業生と卒業生は、卒業後も卒業しています。 "[" post_title "] =>"パスタトマトモッツァレッラ "[" post_excerpt "] =>ストリング(0)" "[" post_status "ストリングclita kasd gubergren、海のタキマタsanctus est Lorem ipsum dolor sit amet。 ["post_password"] =>文字列(0) "" ping_status "] =>文字列(7)"公開 "[" comment_status "] =>文字列(6) "" ["post_modified"] =>文字列(0) "" ["post_name"] =>文字列(2) "53" ["to_ping"] =>文字列(0) 19 ")" 2017-07-07 20:59:08 "[" post_modified_gmt "] =>文字列(19)" 2017-07-07 18:59:08 "[" post_content_filtered "] =>文字列(0)" " ["post_parent"] => string(12) "specialties" ["post_parent"] => int(0)["guid"] =>文字列(57) "" ["menu_order"] => int "post_mime_type"] =>ストリング(0) "" ["comment_count"] =>ストリング(1) "0" ["フィルター"] =>ストリング(3) "未加工"} [4] =>オブジェクト(WP_Post) "post_date"] =>文字列(19) "2017-07-07 20:1" [post_author "] =>文字列(1)" 1 "[" post_date "] => int(51) "" post_content "] =>文字列(591)" Lorem ipsum do "、" ["post_date_gmt"] =>文字列(19) "2017-07-07 18:56:44"それは、あなたの恋人と一緒に過ごすことができます。卒業生と卒業生は、卒業後も卒業しています。 Stet clita kasd gubergren、海の傷跡はありません。Lorem ipsum dolor sit amet。 Lorem ipsum dolle sitet、consetetur sadipscing elitr、sidipscing elitr、sidipscing elitr、sidipscingエリート、sidipscingエリート、sidipscingエリート、sidipscingエリート、エイミードエリート、エリート、エイリアンエリート、卒業生と卒業生は、卒業後も卒業しています。 Stet clita kasd gubergren、海の傷跡はありません。Lorem ipsum dolor sit amet。"" ["post_status"] => string(7) "publish" ["comment_status"] =>文字列(9) "ハンバーガー" ["post_excerpt"] =>文字列(0) ["post_password"] =>文字列(0) "" ["post_name"] =>文字列(9) "hamburger" ["to_ping" "" ["post_modified"] =>文字列(19) "2017-07-07 20:56:44" ["post_modified_gmt"] =>文字列(0) "" ["pinged"] =>文字列(0) (0)["guid"] =>文字列(19) "2017-07-07 18:56:44" ["post_content_filtered"] =>文字列(0) "" ["post_parent"] => int ["post_mime_type"] =>文字列(0) "" ["comment_count"] = "文字列(57)" "[" menu_order "] => int(0)[" post_type " (0) "" ["m"] =>文字列(0) "" ["エラー"] " (0) "" ["subpost_id"] =>文字列(0) "" ["サブポスト"] =>文字列(0) (0) "" ["static"] =>文字列(0) "" ["名前"] =>文字列(0) "pagename"] =>ストリング(0) "" ["page_id"] => int(0)["second"] =>ストライド"" "" "="文字列(0) "" ["日"] => int(0)["monthnum"] => ["tag"] =>文字列(0)["year"] => int(0)["w"] => int(0)["category_name"] =>文字列(0) "" ["author"] => string(0) "" ["cat"] =>文字列(0) "" ["tag_id"] =>文字列(0) ( "meta_key"] =>文字列(0) "" ["paged"] => int(0) "" ["feed"] =>文字列(0) ["s" "] =>文字列(0)" "[" sentence "] =>文字列(0)" "[" meta_value "] =>文字列(0) "" "" "[" menu_order "] =>文字列(0)" "[" embed "](文字列(0)" "["タイトル "] =>文字列(0) (0){} ["category__n"] =>配列(0){} ["category__in"] =>配列(0){} ["category__not_in" (0){} ["tag__in"] => array(0){} ["post__not_in"] =>配列(0) "tag_slug__and"] => array(0){} tag_slug__in "{} tag_slug__in" {} tag_slug__and " } ["post_parent__in"] =>配列(0){} ["post_parent__not_in" ( "ignore_sticky_posts"] => bool(false)["suppress_filters"] =>配列(0){} ["author__in"] =>配列bool(true)["update_post_meta_cache"] => bool(true)["lazy_load_term_meta"] => bool(true)["update_post_meta_cache"] => bool(false) > "string"(> 50) "[postscript"] => int(10)["nopaging"] => bool(false)["comments_per_page"] => #7005(6){["queries"] => "DESC"} "[" no_found_rows "] => bool(false)配列(0){} ["クエリ"] =>文字列(3) "AND" ["table_aliases":保護] => (WP_Meta_Query)#7004(9){["queries"] = "string"(2) "ID"} = "文字列(8)" "wp_posts" ["primary_id_column" NULL] ["primary_table"] => NULL ["primary_id_column"] => NULL ["table_aliases"]>配列(0){} ["relation"] => NULL ["meta_table"] => NULL ["meta_id_column" ":protected] =>配列(0){} [" cla => bool(false)["request"] =>文字列(259) "を使用しています。 SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts WHERE 1 = 1 AND wp_posts.post_type = '投稿' AND(wp_posts.post_status = '公開'またはwp_posts.post_status = 'acf-disabled' OR wp_posts.post_status = 'プライベート')ORDER BY wp_posts 。post_date DESC LIMIT 0、10 "[" posts "] =>配列(0){} [" post_count "] => int(0) int "0" ["max_num_pages"] => int(0)["現在のコメント"] => int(0)[" ( "is_preview"] => bool(false)["is_page"] => bool(false)["is_archive"] => "max_num_comment_pages"] => int(0)["is_single"] => bool bool(false)["is_dear"] => bool(false)["is_dear"] => bool(false) bool(false)["is_time"] => bool(false)["is_author"] => bool(false)["is_category"] => bool(false)["is_tag"] => bool(false)["is_tax"] => bool (false)["is_trackback"] => bool(false)["is_home"())["is_search"] => bool(false)["is_feed"] => bool(false)["is_comment_feed"] => "" => bool(true)["is_404"] => bool(false)["is_embed"] => bool(false)["is_paged"] => bool(false)["is_admin"] => bool => bool(false)["is_attachment"] => bool(false)["is_singular"] => bool(false)["is_robots"] => bool(false)["is_posts_page"] => bool(false) ["query_vars_hash": "WP_Query":private] => string(32) "efaea6907a432061160b874915d6ab95" ["query_vars_changed": "WP_Query":private] => bool(false)["is_post_type_archive"] => bool(false) {0} =>文字列(15)=>文字列(15)=>列挙型() (2){[0] =>文字列(16) "init_query_flags" [1] = "文字列(18)" "query_vars_hash" > string(15) "parse_tax_query"}}

+0

これが役に立つかもしれません:https://digwp.com/2011/05/loops/ – Difster

答えて

0

query_posts()はグローバル$ wp_queryを作成します。 $クエリは異なるWP_Queryオブジェクトです。また、コンストラクタ引数は私にとって間違っているようです。

不正な$ queryオブジェクトがあると思います。 $ queryのvar_dumpの投稿は、クエリの結果ではなく、あなたがコンストラクタで渡した間違った引数です。あなたは単に新しいWP_Queryにargsを直接送るquery_posts()は必要ありません。

$args = array(
    'post_type' => 'specialities', 
    'posts_per_page' => -1 
); 
$query = new WP_Query($args); 
+0

は、あなたの答えをありがとう:)今は働いています – Patrick

0

クエリでは、2つの関数query_posts()とWP_Query()を使用します。

$args = query_posts(array(
     'post_type' => 'specialities', 
     'posts_per_page' => -1 
    )); 
$query = new WP_Query($args); 

query_posts()とWP_Query()は、それぞれ異なる機能です。

あなたはコード

$args = array(
    'post_type' => 'specialities', 
    'posts_per_page' => -1 
); 
$query = new WP_Query($args); 

のRef次使用することができます。 https://codex.wordpress.org/User:JamesVL/query_posts

- - https://codex.wordpress.org/Class_Reference/WP_Query

関連する問題