我正试图根据自定义字段的值来订购我的“gyorshirek”帖子。我从json字段中获取此字段的值。我创建了一个基本函数,该函数应该在WordPress加载时更新此字段,但由于某些原因,它不能正常工作。
function top_lista_valtozas(){
$args = array(
\'post_type\' => \'gyorshirek\', // Only get the posts
\'post_status\' => \'publish\', // Only the posts that are published
\'posts_per_page\' => -1 // Get every post
);
$posts=get\\u posts($参数);
foreach ( $posts as $post ) {
$ticker = get_the_title();
$url = \'https://api.portfolio.hu/chart?ticker=\' . $ticker ;
$token = \'removed\';
$header = array(
\'headers\' => array(
\'Authorization\' => \'Bearer \' . $token,
),
);
$response = wp_remote_get($url, $header);
$body = wp_remote_retrieve_body( $response );
$http_code = wp_remote_retrieve_response_code( $response );
$formatted_json = json_decode($body, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
if (isset($formatted_json[\'change_percent\'])) {
// Run a loop and update every meta data
// update_post_meta( $post->ID, \'ceg_valtozas\', $formatted_json[\'change_percent\'] );
update_field(\'ceg_valtozas\', $formatted_json[\'change_percent\']);
}
}
}//钩住init操作并运行functionadd\\u操作(\'init\',\'top\\u lista\\u valtozas\');
如果我不得不胡乱猜测,我会认为问题出在If语句上,但我不确定如何解决它。有什么建议吗?
谢谢