The plugin search and filter, doesn't retrieve author_meta
. So i need to add post_meta
from author_meta
. Is it possible?
EDIT
I create user_meta in this way:
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' );
Now i need to set 'company' as a post_meta.
EDIT
I have added in functions.php your code, and i set every three minutes WP Cron but i didn't found MySql table 'genere' in postmeta. I have changed 'company', now is 'genere', but it's the same.
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');
}
EDIT
Here the solution: User meta to post