插件search and filter, 无法检索author_meta
. 所以我需要补充post_meta
从…起author_meta
. 有可能吗?
编辑我以这种方式创建user\\u meta:
function custom_user_profile_fields($user){
$previous_value = \'\';
if( is_object($user) && isset($user->ID) ) {
$previous_value = get_user_meta( $user->ID, \'company\', true );
}
?>
<h3>Extra profile information</h3>
<table class="form-table">
<tr>
<th><label for="company">Company Name</label></th>
<td>
<input type="text" class="regular-text" name="company" value="<?php echo esc_attr( $previous_value ); ?>" id="company" /><br />
<span class="description">Where are you?</span>
</td>
</tr>
</table>
<?php
}
add_action( \'show_user_profile\', \'custom_user_profile_fields\' );
add_action( \'edit_user_profile\', \'custom_user_profile_fields\' );
add_action( "user_new_form", "custom_user_profile_fields" );
function save_custom_user_profile_fields($user_id){
if(!current_user_can(\'manage_options\'))
return false;
# save my custom field
if( isset($_POST[\'company\']) ) {
update_user_meta( $user_id, \'company\', sanitize_text_field(
$_POST[\'company\'] ) );
} else {
//Delete the company field if $_POST[\'company\'] is not set
delete_user_meta( $user_id, \'company\', $meta_value );
}
}
add_action(\'user_register\', \'save_custom_user_profile_fields\');
add_action( \'personal_options_update\', \'save_custom_user_profile_fields\' );
add_action( \'edit_user_profile_update\', \'save_custom_user_profile_fields\' );
现在我需要将“company”设置为post\\u meta。编辑我在函数中添加了。php您的代码,我每三分钟设置一次WP Cron,但我在Posteta中没有找到MySql表“genre”。我改了“公司”,现在是“通用”,但它是一样的。
function add_cron_recurrence_interval( $schedules ) {
$schedules[\'every_three_minutes\'] = array(
\'interval\' => 180,
\'display\' => __( \'Every 3 Minutes\', \'textdomain\' )
);
return $schedules;
}
add_filter( \'cron_schedules\', \'add_cron_recurrence_interval\' );
function author_company_post_sync() {
global $wpdb;
$posts= $wpdb->get_results("SELECT ID,post_author FROM ".$wpdb-
>prefix."posts");
foreach ($posts as $post) {
$company = get_user_meta($post->post_author, \'genere\', true);
update_user_meta($post->ID, \'genere\', $company);
}
}
// schedule with WP Cron to run sync callback once daily...
if (!wp_next_scheduled(\'author_company_post_sync\')) {
wp_schedule_event( time(), \'every_three_minutes\',
\'author_company_post_sync\');
}
编辑解决方案:User meta to post