在 WordPress 自定义中遇到错误 Post
Facing Error in WordPress Custom Post
我在自定义 post 类型中遇到问题 我编写 wordpress 自定义代码 post 类型一切正常,但我想让全局代码随处调用。但是当我试图制作 2 个不同的文件以使代码全局化然后显示错误“500 错误”
这是代码
$custom_terms = get_field('portfolio_gallery_category_name');
print_r(get_field('portfolio_gallery_category_name'));
foreach($custom_terms as $custom_term):
wp_reset_query();
$args = array('post_type' => 'portfolio',
'tax_query' => array(
array(
'taxonomy' => 'portfolio_type',
'field' => 'term_id',
'terms' => $custom_term->term_id,
),
),
);
$loop = new WP_Query($args);
include('templates-sections/portfolios.php');
其他全局文件名中剩余的代码是templates-sections/portfolios.php
<?php
error_reporting(E_ALL);
if($loop->have_posts()): ?>
<?php while($loop->have_posts()) : $loop->the_post();
?>
<div class="col-lg-3 col-md-4 col-sm-6 p-0 scale-anm" data-aos="fade-zoom">
<a href="<?php the_post_thumbnail_url('full'); ?>" data-toggle="lightbox" data-gallery="example-gallery">
<img src="<?php the_post_thumbnail_url('full'); ?>" class="img-responsive" /></a>
</div>
<?php endwhile; ?>
<?php endif; ?>
<? endforeach; ?>
我已经报告了所有错误,但同样的事情显示“500”错误任何人都可以帮助解决这个问题。
我知道很多人都有解决方案,有人解决了这个小问题。
提前致谢。
您可以在第二个文件中创建一个函数并在第一个文件中调用它。
<?php
$custom_terms = get_field('portfolio_gallery_category_name');
print_r(get_field('portfolio_gallery_category_name'));
include('templates-sections/portfolios.php');
foreach($custom_terms as $custom_term):
wp_reset_query();
$args = array('post_type' => 'portfolio',
'tax_query' => array(
array(
'taxonomy' => 'portfolio_type',
'field' => 'term_id',
'terms' => $custom_term->term_id,
),
),
);
$loop = new WP_Query($args);
myFunction( $loop );
endforeach;
?>
你的第二个文件
<?php
error_reporting(E_ALL);
function myFunction( $loop ) {
if($loop->have_posts()):
while($loop->have_posts()) : $loop->the_post();
?>
<div class="col-lg-3 col-md-4 col-sm-6 p-0 scale-anm" data-aos="fade-zoom">
<a href="<?php the_post_thumbnail_url('full'); ?>" data-toggle="lightbox" data-gallery="example-gallery">
<img src="<?php the_post_thumbnail_url('full'); ?>" class="img-responsive" /></a>
</div>
<?php endwhile;
endif;
}
?>
我在自定义 post 类型中遇到问题 我编写 wordpress 自定义代码 post 类型一切正常,但我想让全局代码随处调用。但是当我试图制作 2 个不同的文件以使代码全局化然后显示错误“500 错误”
这是代码
$custom_terms = get_field('portfolio_gallery_category_name');
print_r(get_field('portfolio_gallery_category_name'));
foreach($custom_terms as $custom_term):
wp_reset_query();
$args = array('post_type' => 'portfolio',
'tax_query' => array(
array(
'taxonomy' => 'portfolio_type',
'field' => 'term_id',
'terms' => $custom_term->term_id,
),
),
);
$loop = new WP_Query($args);
include('templates-sections/portfolios.php');
其他全局文件名中剩余的代码是templates-sections/portfolios.php
<?php
error_reporting(E_ALL);
if($loop->have_posts()): ?>
<?php while($loop->have_posts()) : $loop->the_post();
?>
<div class="col-lg-3 col-md-4 col-sm-6 p-0 scale-anm" data-aos="fade-zoom">
<a href="<?php the_post_thumbnail_url('full'); ?>" data-toggle="lightbox" data-gallery="example-gallery">
<img src="<?php the_post_thumbnail_url('full'); ?>" class="img-responsive" /></a>
</div>
<?php endwhile; ?>
<?php endif; ?>
<? endforeach; ?>
我已经报告了所有错误,但同样的事情显示“500”错误任何人都可以帮助解决这个问题。
我知道很多人都有解决方案,有人解决了这个小问题。
提前致谢。
您可以在第二个文件中创建一个函数并在第一个文件中调用它。
<?php
$custom_terms = get_field('portfolio_gallery_category_name');
print_r(get_field('portfolio_gallery_category_name'));
include('templates-sections/portfolios.php');
foreach($custom_terms as $custom_term):
wp_reset_query();
$args = array('post_type' => 'portfolio',
'tax_query' => array(
array(
'taxonomy' => 'portfolio_type',
'field' => 'term_id',
'terms' => $custom_term->term_id,
),
),
);
$loop = new WP_Query($args);
myFunction( $loop );
endforeach;
?>
你的第二个文件
<?php
error_reporting(E_ALL);
function myFunction( $loop ) {
if($loop->have_posts()):
while($loop->have_posts()) : $loop->the_post();
?>
<div class="col-lg-3 col-md-4 col-sm-6 p-0 scale-anm" data-aos="fade-zoom">
<a href="<?php the_post_thumbnail_url('full'); ?>" data-toggle="lightbox" data-gallery="example-gallery">
<img src="<?php the_post_thumbnail_url('full'); ?>" class="img-responsive" /></a>
</div>
<?php endwhile;
endif;
}
?>