我最近发现了Scribu的Posts 2 Posts 插件,这似乎正是我所寻找的,以便连接一个大型编辑网站的页面和帖子。
但我无法让它发挥作用,这令人沮丧,因为这个原则似乎真的很容易。我跟着wiki basic usage example, 在我的功能中。php我有:
function my_connection_types() {
if ( !function_exists( \'p2p_register_connection_type\' ) )
return;
p2p_register_connection_type( array(
\'from\' => \'post\',
\'to\' => \'page\'
) );
}
add_action( \'init\', \'my_connection_types\', 100 );
和第页。php:
$connected = new WP_Query( array(
\'post_type\' => \'post\',
\'connected_from\' => get_queried_object_id()
) );
echo \'<p>Related posts:</p>\';
echo \'<ul>\';
while( $connected->have_posts() ) : $connected->the_post();
echo \'<li>\';
the_title();
echo \'</li>\';
endwhile;
echo \'</ul>\';
wp_reset_postdata();
我有一个帖子叫做“玉米饼”,我把它连接到了一个叫做“关于”的页面。
当我进入“关于”页面时,我会看到“相关帖子:”,但之后就没有其他内容了(例如,我的玉米卷在哪里?)
A.print_r( $connected )
给出以下内容:
WP_Query Object ( [query_vars] => Array ( [post_type] => post [connected_from] => 2 [error] => [m] => 0 [p] => 0 [post_parent] => [subpost] => [subpost_id] => [attachment] => [attachment_id] => 0 [name] => [static] => [pagename] => [page_id] => 0 [second] => [minute] => [hour] => [day] => 0 [monthnum] => 0 [year] => 0 [w] => 0 [category_name] => [tag] => [cat] => [tag_id] => [author_name] => [feed] => [tb] => [paged] => 0 [comments_popup] => [meta_key] => [meta_value] => [preview] => [s] => [sentence] => [fields] => [category__in] => Array ( ) [category__not_in] => Array ( ) [category__and] => Array ( ) [post__in] => Array ( ) [post__not_in] => Array ( ) [tag__in] => Array ( ) [tag__not_in] => Array ( ) [tag__and] => Array ( ) [tag_slug__in] => Array ( ) [tag_slug__and] => Array ( ) [meta_query] => Array ( ) [ignore_sticky_posts] => [suppress_filters] => [cache_results] => 1 [update_post_term_cache] => 1 [update_post_meta_cache] => 1 [posts_per_page] => 10 [nopaging] => [comments_per_page] => 50 [no_found_rows] => [order] => DESC [orderby] => il_posts.post_date DESC ) [tax_query] => WP_Tax_Query Object ( [queries] => Array ( ) [relation] => AND ) [post_count] => 0 [current_post] => -1 [in_the_loop] => [comment_count] => 0 [current_comment] => -1 [found_posts] => 0 [max_num_pages] => 0 [max_num_comment_pages] => 0 [is_single] => [is_preview] => [is_page] => [is_archive] => [is_date] => [is_year] => [is_month] => [is_day] => [is_time] => [is_author] => [is_category] => [is_tag] => [is_tax] => [is_search] => [is_feed] => [is_comment_feed] => [is_trackback] => [is_home] => 1 [is_404] => [is_comments_popup] => [is_paged] => [is_admin] => [is_attachment] => [is_singular] => [is_robots] => [is_posts_page] => [is_post_type_archive] => [query_vars_hash] => 90a220b2f180d3ea6ccbd9473e26ec4c [query_vars_changed] => [query] => Array ( [post_type] => post [connected_from] => 2 ) [request] => SELECT SQL_CALC_FOUND_ROWS il_posts.*, il_p2p.* FROM il_posts INNER JOIN il_p2p WHERE 1=1 AND il_posts.post_type = \'post\' AND (il_posts.post_status = \'publish\' OR il_posts.post_status = \'private\') AND il_posts.ID = il_p2p.p2p_to AND il_p2p.p2p_from IN (2) ORDER BY il_posts.post_date DESC LIMIT 0, 10 [posts] => Array ( ) )
我错过了什么?
ps.Wordpress 3.1.1,Posts 2 Posts 0.7和PHP 5.3.3