时间:2019-11-07 00:23:32

标签: php arrays wordpress string

我正在创建一个WP网站。在首页中,出现错误:

  

警告:在第108行的/home2/siilverp/public_html/wp-content/themes/mts_steadyincome/page-home.php中为foreach()提供了无效参数

这是page-home.php的代码:

  <?php if(!empty($mts_options['mts_featured_posts']) && !empty($mts_options['mts_featured_post_cat'])) { ?>
                <div class="home_article">
                    <?php 
                    foreach ( $mts_options['mts_featured_post_cat'] as $cat_id ) {
                        $featured_query = new WP_Query( apply_filters( 'steadyincome_featured_posts_query', array(
                            'cat' => $cat_id,
                            'posts_per_page' => 1
                        ) ) );

现在,我发现我必须键入var_dump。然后,出现:

  

array(84){[“” mts_logo“] =>字符串(0)”“ [” mts_favicon“] =>字符串(0)”“ [” [mts_touch_icon“] =>字符串(0)”“ [” mts_metro_icon “] =>字符串(0)”“ [[” mts_twitter_username“] =>字符串(0)”“ [” mts_feedburner“] =>字符串(0)”“ [” mts_header_code“] =>字符串(0)”“ [ “ mts_analytics_code”] =>字符串(0)“” [“ [” mts_ajax_search“] =>字符串(1)” 0“ [” mts_sensitive“] =>字符串(1)” 1“ [” mts_rtl“] =>字符串(1 )“ 0” [“ mts_shop_products”] =>字符串(1)“ 9” [“ mts_prefetching”] =>字符串(1)“ 0” [“ mts_lazy_load”] =>字符串(1)“ 0” [“ mts_lazy_load_thumbs” ] =>字符串(1)“ 0” [“ mts_lazy_load_content”] =>字符串(1)“ 0” [“ mts_async_js”] =>字符串(1)“ 1” [“ mts_remove_ver_params”] =>字符串(1)“ 1“ [” mts_optimize_wc“] =>字符串(1)” 1“ [” mts_color_scheme“] =>字符串(7)”#3fc5a4“ [” mts_layout“] =>字符串(8)” cslayout“ [” mts_background“] => array(10){[“” color“] => string(7)” #ffffff“ [” use“] => string(7)” pattern“ [” image_pattern“] => string(4)” nobg“ [“ image_upload”] =>字符串(0)“” [“重复”] =>字符串(6)“重复” [“附件”] =>字符串(6)“滚动l“ [” position“] => string(8)”左上“ [” size“] => string(5)” cover“ [” gradient“] => array(3){[” from“] => string(7)“ #ffffff” [“至”] => string(7)“#000000” [“ direction”] => string(10)“ horizo​​ntal”} [“ parallax”] => string(1)“ 0“} [” mts_custom_css“] =>字符串(0)”“ [” mts_lightbox“] =>字符串(1)” 0“ [” mts_sticky_nav“] =>字符串(1)” 0“ [” mts_show_primary_nav“] = > string(1)“ 1” [“ mts_show_footer_nav”] => string(1)“ 1” [“ mts_header_section2”] => string(1)“ 1” [“ mts_header_bottom_text”] => string(17)“下载我的电子书“ [” mts_header_bottom_button_text“] =>字符串(20)”今天开始赚钱!“ [“ mts_header_bottom_button_link”] =>字符串(1)“#” [“ mts_banner_show”] =>字符串(1)“ 1” [“ mts_banner_image”] =>字符串(81)“ https://seiscifrasonline.com/wp-content/themes/mts_steadyincome/images/header.jpg” [“ mts_banner_title” ] =>字符串(34)“今天开始赚取稳定收入!” [“ mts_banner_texts”] =>字符串(156)“ Lorem ipsum dolor sit amet,consectetur adipiscing elit。Morbi at nisl lorem,vel porttitor justo。Nunc non mauris elit。Nam enim massa commodo ut placerat。” [“ mts_button_text”] =>字符串(16)“从这里开始” [[mts_banner_button_bg“] =>字符串(7)”#FF9742“ [” mts_arrow_image“] =>字符串(80)” https://seiscifrasonline.com/wp-content/themes/mts_steadyincome/images/arrow.png“ [ “ mts_form_image”] =>字符串(80)“ https://seiscifrasonline.com/wp-content/themes/mts_steadyincome/images/money.png” [“ mts_ribbon_show”] =>字符串(1)“ 1” [“ mts_banner2_show”] =>字符串(1)“ 1” [“ mts_social_title”] => string(66)“加入我们的在线社区中的100,000多人!” [“ mts_banner_social”] => array(5){[“ facebook”] => array(5){[“ group_title”] =>字符串(8)“ Facebook” [“ group_sort”] =>字符串(1)“ 1“ [” mts_banner_icon_title“] =>字符串(8)” Facebook“ [” mts_banner_icon“] =>字符串(8)” facebook“ [” mts_banner_icon_link“] =>字符串(1)”#“} [” twitter“] => array(5){[“ group_title”] => string(7)“ Twitter” [“ group_sort”] => string(1)“ 2” [“ mts_banner_icon_title”] => string(7)“ Twitter” [ “ mts_banner_icon”] =>字符串(7)“ twitter” [“ mts_banner_icon_link”] =>字符串(1)“#”} [“ gplus”] => array(5){[“” group_title“] =>字符串(11 )“ Google Plus” [“ group_sort”] =>字符串(1)“ 3” [“ mts_banner_icon_title”] =>字符串(11)“ Google Plus” [“ mts_banner_icon”] =>字符串(11)“ google-plus” [“ mts_banner_icon_link”] =>字符串(1)“#”} [“ youtube”] =>数组(5){[“” group_title“] =>字符串(7)” YouTube“ [” group_sort“] =>字符串( 1)“ 4” [“ mts_banner_icon_title”] =>字符串(7)“ YouTube” [“ mts_banner_icon”] =>字符串(12)“ youtube-play” [“ mts_banner_icon_link”] =>字符串(1)“#”} [“ rss”] => array(5){[“ group_title “] =>字符串(3)” RSS“ [” group_sort“] =>字符串(1)” 5“ [” mts_banner_icon_title“] =>字符串(3)” RSS“ [” mts_banner_icon“] =>字符串(3) “ rss” [“ mts_banner_icon_link”] =>字符串(1)“#”}} [“ mts_books_title”] =>字符串(51)“ John Smith推荐的读物” [[“ mts_books_image”] =>字符串(0)“” [“ mts_more_book_link”] =>字符串(1)“#” [“ mts_more_book_text”] =>字符串(10)“更多书籍” [“ mts_featured_posts”] =>字符串(1)“ 1” [“ mts_featured_post_cat”] =>字符串(1)“ 1” [“ mts_featured_post_dedup”] =>字符串(1)“ 0” [“ mts_first_footer”] =>字符串(1)“ 0” [“ mts_first_footer_num”] =>字符串(1)“ 4” [ “ mts_footer_slider”] =>字符串(0)“” [“ [mts_copyrights”] =>字符串(73)“ TheMy by MyThemeShop” [[mts_home_post_layout“] =>字符串(8)” layout-1“ [” mts_full_posts“] = >字符串(1)“ 0” [“ mts_pagenavigation_type”] =>字符串(1)“ 1” [“ mts_home_headline_meta_info”] => array(2){[“启用”] => array(3){[“作者” ] =>字符串(11)“作者名称” [“日期”] =>字符串(4)“日期” [“注释”] =>字符串(13)“注释计数”} [“已禁用”] => array( 0){} } [“ mts_single_post_layout”] =>字符串(0)“” [“ mts_single_headline_meta_info”] => array(2){[“” enabled“] => array(4){[”“ author”] => string(11)“作者名称“ [”日期“] =>字符串(4)”日期“ [”类别“] =>字符串(10)”类别“ [”评论“] =>字符串(13)”评论计数“} [”已禁用“] => array(0){}} [” mts_breadcrumb“] =>字符串(1)” 1“ [” mts_author_comment“] =>字符串(1)” 1“ [” mts_comment_date“] =>字符串(1) “ 1” [“ mts_home_social_buttons”] =>字符串(1)“ 1” [“ mts_social_button_position”] =>字符串(3)“ top” [“ mts_social_buttons”] => array(2){[“启用”] => array(5){[“ facebookshare”] =>字符串(14)“ Facebook Share” [“ facebook”] =>字符串(13)“ Facebook Like” [“ twitter”] =>字符串(7)“ Twitter” [ “ gplus”] =>字符串(11)“ Google Plus” [“ pinterest”] =>字符串(9)“ Pinterest”} [“ disabled”] => array(2){[“ linkedin”] =>字符串( 8)“ LinkedIn” [“ stumble”] =>字符串(11)“ StumbleUpon”}} [>“ mts_posttop_adcode”] =>字符串(0)“” [“ mts_posttop_adcode_time”] =>字符串(1)“ 0” [“ mts_postend_adcode“] =>字符串(0)”“ [” mts_postend_ adcode_time“] =>字符串(1)” 0“ [” mts_custom_sidebars“] =>字符串(0)”“ [” mts_sidebar_for_home“] =>字符串(0)”“ [” [mts_sidebar_for_post“] =>字符串(0)” “” [“ mts_sidebar_for_page”] =>字符串(0)“” [“ mts_sidebar_for_archive”] =>字符串(0)“” [“ [mts_sidebar_for_category”] =>字符串(0)“” [“ [mts_sidebar_for_tag”] =>字符串(0 )“” [“ mts_sidebar_for_date”] =>字符串(0)“” [“ mts_sidebar_for_author”] =>字符串(0)“” [“ mts_sidebar_for_search”] =>字符串(0)“” [“ mts_sidebar_for_notfound”] =>字符串(0)“” [“ mts_sidebar_for_shop”] =>字符串(12)“ shop-sidebar” [“ mts_sidebar_for_product”] =>字符串(15)“ product-sidebar” [“ last_tab”] => int(0)}   警告:第108行的/home2/siilverp/public_html/wp-content/themes/mts_steadyincome/page-home.php中为foreach()提供的参数无效

从那里,我不知道该怎么办。我对编程一无所知。

2 个答案:

答案 0 :(得分:1)

它会发出警告,因为您的[“ mts_featured_post_cat”] =>字符串(1)是不是数组的字符串。

答案 1 :(得分:0)

$mts_options['mts_featured_post_cat']是一个字符串。您必须是对象或数组才能使用foreach

如果它始终是一个值,那么它将起作用:

$cat_id = $mts_options['mts_featured_post_cat'];

  $featured_query = new WP_Query( 
     apply_filters( 
        'steadyincome_featured_posts_query', array(
           'cat' => $cat_id,
           'posts_per_page' => 1
        )
     ) 
  );