我有一个Wordpress网站,它非常依赖人际关系。这是一个唱片公司网站,艺术家可以在该网站上进行巡演、评论、专辑发行和存储物品。
我找到了插件Posts to Posts by Scribu 这似乎是我想要的,但我不知道如何正确使用它。Scribu发布了示例代码,但由于某些原因,我无法理解它。
下面是一个我想用我正在工作的网站做什么的例子。
Tours Page.
旅游项目具有标题和名为“tickets\\u link”的自定义元字段
加载tours页面后,所有tours都将显示其指定的艺术家,如果有tickets链接,则也会显示该链接。
如果这里有人能理解Scribu网站上发布的插件代码,然后向我解释,我将不胜感激。
<小时>Here is my code from the functions.php file registering the connections:
function my_connection_types() {
if ( !function_exists(\'p2p_register_connection_type\') )
return;
p2p_register_connection_type( \'tours\', \'artists\' );
p2p_register_connection_type( \'homepage_carousel\', \'artists\' );
p2p_register_connection_type( \'duka\', \'artists\' );
p2p_register_connection_type( \'products_carousel\', \'artists\' );
}
add_action(\'init\', \'my_connection_types\', 100);
<小时>
Pseudo code to show what I want to do in my code: 使用循环获取my tours custom post archive中的所有tours,该循环将所有tours添加到站点每个巡演都与一位艺术家相关,因此显示特定艺术家的所有巡演项目以标题(艺术家名称)的形式出现,每个项目都是一个巡演,它使用元盒在后端与特定艺术家相关,元盒显示注册连接的结果
Further update along with code I am using and print_r values. 我在查询的print\\r内容中显示了相关的艺术家,而之前我没有显示。当我进行print\\r时,会显示以下内容,但无法访问数据。
[connected_connected] => Array ( [0] => stdClass Object ( [ID] => 245 [post_author] => 1 [post_date] => 2011-03-10 13:55:23 [post_date_gmt] => 2011-03-10 13:55:23 [post_content] => [post_title] => 1200 Techniques [post_excerpt] => [post_status] => publish [comment_status] => closed [ping_status] => closed [post_password] => [post_name] => 1200-techniques [to_ping] => [pinged] => [post_modified] => 2011-03-10 13:55:23 [post_modified_gmt] => 2011-03-10 13:55:23 [post_content_filtered] => [post_parent] => 0 [guid] => http://localhost/testdev/?post_type=artists&p=245 [menu_order] => 0 [post_type] => artists [post_mime_type] => [comment_count] => 0 [p2p_id] => 2 [p2p_from] => 215 [p2p_to] => 245
The code I am using to relate artists with tours is the following: $connected = new WP_Query(array(
\'post_type\' => \'tours\',
\'nopaging\' => true,
\'each_connected\' => array(
\'post_type\' => \'artists\',
\'nopaging\' => true,
),
\'suppress_filters\' => false
));
while( $connected->have_posts() ): $connected->the_post();
the_title();
echo "<br />";
endwhile;
print_r($connected); // Print_r for showing contents of post object.
<小时>
Update for Scribu: $args = array
(
\'post_type\' => \'tours\',
\'nopaging\' => true,
\'suppress_filters\' => false
);
$connected = new WP_Query($args);
while($connected->have_posts()): $connected->the_post();
the_title();
echo "<br />";
foreach ($connected->connected AS $tour_item)
{
echo get_the_title($tour_item->ID);
echo "<br />";
}
endwhile;