Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.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
Wordpress自定义字段组未显示所有数据_Wordpress_Advanced Custom Fields - Fatal编程技术网

Wordpress自定义字段组未显示所有数据

Wordpress自定义字段组未显示所有数据,wordpress,advanced-custom-fields,Wordpress,Advanced Custom Fields,我已经为这个问题烦恼了好几天了,希望能在这里找到解决办法 我试图显示来自自定义字段组的数据。这是我试图实现的一个示例布局 基本上,我试图显示其中的20++列。然而,我从这个自定义字段组中只得到了大约11个字段 以下是我的页面模板代码: <?php /* Template Name: Branches Page */ get_header(); global $currentCity; $registration_link = get_post_meta(96, 'registr

我已经为这个问题烦恼了好几天了,希望能在这里找到解决办法

我试图显示来自自定义字段组的数据。这是我试图实现的一个示例布局

基本上,我试图显示其中的20++列。然而,我从这个自定义字段组中只得到了大约11个字段

以下是我的页面模板代码:

<?php
/* Template Name: Branches Page */  

get_header();

global $currentCity;

$registration_link = get_post_meta(96, 'registration_link', true);
$registration_text = get_post_meta(96, 'registration_text', true);


$thumbnail_url  = wp_get_attachment_url( get_post_thumbnail_id( $post->ID ) );
?>
    <!-- FEATURE IMAGE
    ================================================== -->
    <?php if( has_post_thumbnail() ) { // check for feature image ?>

    <section class="feature-image" style="background: url('<?php echo $thumbnail_url; ?>') no-repeat; background-size: cover;" data-type="background" data-speed="2">
        <h1 class="page-title"><?php the_title(); ?></h1>
    </section>

    <?php } else { // fallback image ?>

    <section class="feature-image feature-image-default" data-type="background" data-speed="2">
        <h1 class="page-title"><?php the_title(); ?></h1>
    </section>

    <?php } ?>

    <!-- MAIN CONTENT
    ================================================== -->
    <div class="container">
        <div class="row" id="primary">

            <div id="content" class="col-sm-12>

                <section class="main-content">

                    <?php while ( have_posts() ) : the_post(); ?>

                        <?php the_content(); ?>

                    <?php endwhile; // end of the loop ?>

                    <?php $loop = new WP_Query( array( 'post_type' => 'branches_locations', 'orderby'=>'post_id', 'order'=>'ASC' ) ); ?>


                    <div class="resource-row clearfix">
                        <?php while( $loop->have_posts() ) : $loop->the_post(); ?>

                        <?php
                            $resource_url = get_field('resource_url');
                            $address = get_field('address');
                            $city    = get_field('city');
                            $branch_image = get_field('branch_image');  
                            $senior_high_ready = get_field('senior_high_ready');

                        ?>

                        <div class="resource">

                            <?php 
                            if( $city <> $currentCity )
                            {
                            ?>
                                <h2>
                                    <?php echo $city; ?>
                                </h2>

                            <?php 
                            }
                            else
                            {
                            ?>  
                                <h2 class="hidden-dummy-header">
                                    Blank
                                <h2>    
                            <?php
                            }
                            ?>

                            <h3><?php the_title(); ?></h3>

                            <p><?php echo $address; ?></p>

                            <?php
                            if( $senior_high_ready == True)
                            {
                            ?>
                                <h5 class="senior_high_ready">
                                    SENIOR HIGH READY
                                </h5>

                            <?php 
                            }
                            else
                            {
                            ?>  
                                <h5 class="hidden-dummy-header">
                                    Blank
                                </h5>   
                            <?php
                            }
                            ?>

                            <img src="<?php echo $branch_image[url]; ?>" alt="<?php echo $branch_image[alt]; ?>">

                            <div class="register-link">

                                <a href="<?php echo $registration_link; ?>" class="btn btn-primary"><?php echo $registration_text; ?>
                                </a>

                            </div>

                            <?php $currentCity = $city; ?>
                        </div><!-- resource -->

                        <?php endwhile; ?>

                    </div><!-- resource-row -->

                </section><!-- main-content -->

            </div><!-- content -->

        </div><!-- row -->

    </div><!-- container -->

<?php get_footer(); ?>


默认情况下,WordPress会将每页的posts设置为10,因此一次只能获得10个,除非在代码中的其他地方更改了默认设置。您可以通过将其设置为-1来获取所有帖子。像这样:

 <?php $loop = new WP_Query( array( 'posts_per_page' => -1, 'post_type' => 'branches_locations', 'orderby'=>'post_id', 'order'=>'ASC' ) ); ?>

我希望这有帮助

此外,您可以将其拆分为多行以提高可读性,例如:

<?php
$loop = new WP_Query( array( 
 'posts_per_page' => -1,
 'post_type' => 'branches_locations',
 'orderby'=>'post_id',
 'order'=>'ASC' 
) ); 
?>


顺便说一句,我将其称为自定义帖子类型,而不是自定义字段组。(仅供将来参考,如果您使用该术语,您可能会获得更好的谷歌搜索结果。)

谢谢您的更新。是的,下次将使用自定义帖子类型。