[插件:发布2条帖子]它是怎么工作的?

时间:2011-04-23 作者:mike23

我最近发现了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

1 个回复
最合适的回答,由SO网友:Milo 整理而成

try \'connected\' => get_queried_object_id() instead of \'connected_from\' => get_queried_object_id()

相关推荐

JqueryUi对话框给出未捕获的TypeError:This._addClass不是函数错误

我有一个网站,我们需要一些自定义php编码来连接到外部数据库,以获取几个销售我们产品的供应商的产品评论URL。我们试图实现的基本想法是让用户注册他们的产品,然后如果他们愿意留下评论,就延长保修期。我正在使用XYZScript。com的“插入PHP”插件来实现这一点。该主题最初只加载了jQuery,以避免创建子主题,我们正在php脚本中加载jQueryUI。因此,我们将jQuery加载到文档的标题中,将jQueryUI加载到文档的正文中。我不太确定这是因为加载脚本的顺序造成的,还是其他一些冲突的javasc

[插件:发布2条帖子]它是怎么工作的? - 小码农CODE - 行之有效找到问题解决它

[插件:发布2条帖子]它是怎么工作的?

时间:2011-04-23 作者:mike23

我最近发现了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

1 个回复
最合适的回答,由SO网友:Milo 整理而成

try \'connected\' => get_queried_object_id() instead of \'connected_from\' => get_queried_object_id()

相关推荐

浏览器刷新时删除数据库条目,AJAX PHP jQuery

我有一个表单,在通过ajax提交表单时更新数据库表中的列。一切都很好,数据库表列可以获取信息,但一旦刷新浏览器,信息就会从数据库中删除。如果meta\\u值不存在,但meta\\u值也在提交表单时创建的数据库中,则PHP将执行数据库更新。我希望信息保留在数据库中,直到或除非meta\\u值被删除或不存在。任何见解都将不胜感激。PHPadd_action(\'wp_ajax_hide_this\', \'hide_this_by_id\'); add_action(\'wp_ajax_nopriv_