我正在为woocommerce创建一个自定义主题,我需要能够创建一个迷你产品展示.我在找到woocommerce api的文档时遇到了问题.我有一个逗号分隔的产品ID列表,我需要迭代并按顺序显示每个产品ID的自定义迷你产品显示.
$key_values = get_post_custom_values('rel_products_ids');
//get comma delimited list from product
$rel_product_ids = explode(",", trim($key_values, ","));
// create array of just the product ids
foreach ( $rel_product_ids as $pid ) {
//sequentially get each id and do something with it
$loop = new WP_Query( array( 'post__in' => $pid ) );
// also tried ...
//$loop = new WP_Query( array( 'ID' => $pid ) );
while ( $loop->have_posts() ) : $loop->the_post(); $_product = &new WC_Product( $loop->post->ID );
//do stuff here I …Run Code Online (Sandbox Code Playgroud) 首先让我说我使用的是MySQL(不是事务性的),并且无法更改.此外,为简洁明了,我在这里简化了表格.
在这个例子中,'Lesson'由它的内部属性和一个外部属性组成,它有自己的属性'Readings'.'Readings'拥有自己的密钥依赖属性和三个不同的外部属性(阅读源).
我想避免在这里产生的多态关联,但我无法绕过它.在此示例中,'Reading'表中的'sourceId'将包含三个表"ExternalURL","InternalURL"和"Book"之一的id.此外,字段"polytable"将包含上述"id"来自的表名.
有人可以花一点时间来解释如何解决这种维护RI的问题,还是为了效率而应该留下它?
感谢您的时间和考虑,
蒂姆
-------------
| ExternalURL |
-------------
| id |
| badlink |
| url |
| |
| |
-------------
|
|
|
/ \
------------ ------------- -------------
| Lesson |-------<| Reading |>-------| InternalURL |
------------ ------------- -------------
| id | | id | | id |
| label | | lessonId | | url |
| summary | | sourceId | | |
| lessonOrder| | polytable | | |
| active | | …Run Code Online (Sandbox Code Playgroud)