Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/258.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 警告:array_push()要求参数1为数组,对象在第26行给出_Php_Arrays_Warnings - Fatal编程技术网

Php 警告:array_push()要求参数1为数组,对象在第26行给出

Php 警告:array_push()要求参数1为数组,对象在第26行给出,php,arrays,warnings,Php,Arrays,Warnings,我不完全确定这为什么会出现在我的网页上?我看了代码,但在那一行似乎没有错 这条线就是数组线,有人说这是因为$taxonomy不是数组?但我真的不确定问题出在哪里 以下是php文件: <?php /* Template Name: Portfolio */ ?> <?php get_header(); ?> <?php // Add. Options

我不完全确定这为什么会出现在我的网页上?我看了代码,但在那一行似乎没有错

这条线就是数组线,有人说这是因为$taxonomy不是数组?但我真的不确定问题出在哪里

以下是php文件:

    <?php 
        /*
        Template Name: Portfolio

        */
        ?>
        <?php get_header(); ?>
        <?php

    // Add. Options Variables
    $portfolio_opts = get_post_meta(get_the_ID(), 'portfolio_additional_options', true);
    $is_filtration = is_array($portfolio_opts) && in_array('is_filtration', $portfolio_opts) ? true : false;
    $is_masonry = is_array($portfolio_opts) && in_array('is_masonry', $portfolio_opts) ? 'true' : 'false';

    // Taxonomy Variables
    $taxonomy = 'portfolio_category';
    $taxonomy_term_ID = get_post_meta(get_the_ID(), $taxonomy, true);

    $taxonomy_terms = get_terms( $taxonomy, array(
        'child_of'   => $taxonomy_term_ID,
        'hide_empty' => 0,
        'fields'     => 'ids',
    ) );

    array_push($taxonomy_terms, $taxonomy_term_ID); // add parent category to list

    // WP_QUERY Arguments
    $portfolio_args = array(
        'post_type' => 'portfolio',
        'tax_query' => array(
            array(
                'taxonomy' => $taxonomy,
                'field' => 'id',
                'terms' => $taxonomy_terms
            ),
        ),
        'posts_per_page'      => -1
    );

    $portfolio_query = new WP_Query($portfolio_args);

?>

<!-- BEGIN: SITE BODY -->
<section id="site-body" class="sections portfolio padding-size-l">

    <div class="container">

        <?php if ( $is_filtration ) { ?>

        <!-- BEGIN: FILTERATION -->
        <div class="filters-wrap">
            <ul class="filters nostyle">
                <li><a data-filter="*" class="active"><?php esc_html_e('All', 'lamark'); ?></a></li>
                <?php wp_list_categories(array('child_of' => $taxonomy_term_ID, 'title_li' => '', 'style' => 'none', 'taxonomy' => $taxonomy, 'show_option_none'   => '', 'walker' => new Lamark_Walker_Portfolio_Filter())); ?>
            </ul>
        </div>
        <!-- END: FILTERATION -->

        <?php } ?>

        <!-- BEGIN: PORTFOLIO GRID -->
        <section class="grid clearfix" data-col="<?php echo get_post_meta(get_the_ID(), 'portfolio_columns', true); ?>" data-margin="25" data-height="0.8" data-double-height="1.6" data-masonry="<?php echo $is_masonry; ?>">

            <?php if ( $portfolio_query->have_posts() ) : while ( $portfolio_query->have_posts() ) : $portfolio_query->the_post(); ?>

                <?php get_template_part( 'parts/portfolio-index-entry.inc' ); ?> 

            <?php endwhile; else: ?>

                <p class="entry"><?php printf( esc_html__( 'Ready to publish your first entry? <a href="%1$s">Get started here</a>.', 'lamark' ), esc_url( admin_url() ) ); ?></p> 

            <?php endif; ?>

        </section>
        <!-- END: PORTFOLIO GRID -->

    </div>

</section>
<!-- END: SITE BODY -->

<?php get_footer(); ?>

  • .,'lamark'),esc_url(admin_url());?>

表示如果$taxonomy中的任何一个不存在,get_terms()“将返回WP_错误。”

您能否测试$taxonomy\u terms以确保它是一个数组,如果不打印它是什么,可能如下所示:

if (! is_array($taxonomy_terms)) {
  // show the issue
  die('<pre>'.print_r($taxonomy_terms, 1));
} else {
  // okay, no issue with that array...continue
  array_push($taxonomy_terms, $taxonomy_term_ID); // add parent category to list
}
if(!is_数组($taxonomy_terms)){
//显示问题
模具(''.print_r($taxonomy_terms,1));
}否则{
//好的,阵列没有问题…继续吗
array_push($taxonomy_terms,$taxonomy_term_ID);//将父类别添加到列表中
}

您拥有解决此问题所需的所有信息。你想做什么?什么不起作用?