需要在wp_posts添加字段,添加时候报错:
导入数据库时报错1067 – Invalid default value for ‘post_date’
https://blog.csdn.net/nssddwbzd/article/details/122037461
解决方法:
phpstudy面板-》设置-》配置文件-》mysql.ini
在此文件[client]上面添加如下代码:
sql_mode=ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
页面调用:
<?php $posts = get_posts( "category=7&offset=1&numberposts=2" ); ?> <?php if( $posts ) : ?> <?php foreach( $posts as $post ) : setup_postdata( $post ); ?> <li> <?php the_title(); ?> <?php echo $post->house_price ?>//house_price为自定义字段 </li> <?php endforeach; ?> <?php endif; ?>