gpt4 book ai didi

mysql - 如何在 WordPress 中的自定义字段组内循环

转载 作者:行者123 更新时间:2023-11-29 20:12:31 27 4
gpt4 key购买 nike

我想在 WordPress 页面上模拟以下布局。

enter image description here

但是如何让包围城市充满活力呢?布局设置为在特定状态下,该状态下的所有商店都列在其下方。

在 SQL 上,这可能意味着:

select city where address = "";

我只是不知道如何将我的 SQL 知识转化为 WordPress 动态页面。

到目前为止我的 WordPress 页面代码是:

<section class="main-content">

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

<div class="resource-row clearfix">

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

<?php
$address = get_field('address');

?>
</div><!-- resource-row -->
</section><!-- main-content -->

编辑:

到目前为止,根据上图,我能做的是显示以下内容:

Cupertino 1 Infinite Loop Cupertino, CA

但是,我似乎无法显示该地址所在的州(例如加利福尼亚州)以及该行中的其他地址。

如何使每个州的相应地址显示在其下方?

最佳答案

嗯,如果您共享表结构,将会有很大帮助。假设有三个单独的记录:

  1. 库比蒂诺
  2. 无限循环
  3. 加利福尼亚州库比蒂诺

我们可以这样做:

select group_concat(x separator ' ') address
from (select 'Cupertino 1' x union
select 'Infinite Loop' union
select 'Cupertino, CA') t;

关于mysql - 如何在 WordPress 中的自定义字段组内循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39992590/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com