![](/img/trans.png)
[英]Mass update Wordpress post slug and redirect to the new slug by SQL Query
[英]WordPress XMLRPC - Search Post by Slug and Update
無論如何通過 XMLRPC https://codex.wordpress.org/XML-RPC_WordPress_API/Posts#wp.getPosts搜索帖子
getPosts()似乎沒有使用“名稱”返回。
$args = array(
'name' => 'my-slug',
'number' => 1
);
$post = $wpClient->getPosts( $args );
請讓我知道是否有解決方法,我需要通過 slug 進行搜索,然后通過 XMLRPC 遠程更新這些 slugs。 干杯
我最終使用了方法,這可能會幫助某人並節省時間。將以下代碼粘貼到您要從中獲取數據的域的 functions.php 中
add_filter('xmlrpc_methods', 'clx_xmlrpc_methods');
function clx_xmlrpc_methods($methods) {
$methods['getPostBySlug'] = 'clx_getpost';
return $methods;
}
function clx_getpost($args) {
global $wp_xmlrpc_server;
$slug = $args["slug"];
$pargs = array(
'name' => $slug,
'post_type' => 'post',
'numberposts' => 1
);
$my_posts = get_posts($pargs);
if( $my_posts ) :
return $my_posts; //echo $my_posts[0]->ID;
endif;
}
從您的 XMLRPC 代碼中使用以下代碼從 slug 獲取 POST 數組
$args = array(
'slug' => 'your-post-slug'
);
$postArray = $wpClient->callCustomMethod( 'getPostBySlug', $args );
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.