url:myajax.url?action=myfilter
data:{ qqq : 123,action: 'myfilter' },
var $data = {
action: 'myfilter',
qqq :123 ,
security: myajax.security,
}
$.post(myajax.ajaxurl, $data, function ($response) {
if ($response.success) {
console.info('Ответ от сервера', $response);
} else {
// обработка ошибок
}
});
add_action( 'wp_ajax_myfilter', 'my_filter_function' );
add_action( 'wp_ajax_nopriv_myfilter', 'my_filter_function' );
function my_filter_function() {
$check = check_ajax_referer( 'special-string', 'security' );
if ( empty( $check ) ) {
$error_code = 1;
}
if ( empty( $_POST[ 'qqq' ] ) ) {
$error_code = 2;
}
if ( ! empty( $error_code ) ) {
wp_send_json_error( [ 'error' => $error_code ] );
}
$str = esc_html( $_POST[ 'qqq' ] );
wp_send_json_success( [ 'str' => $str ] );
}
$vals = get_the_field( 'size' );
$vals_args = explode( ',', preg_replace( '/\s+/', '', $vals ) );
if ( !empty( $vals_args ) ) {
$options = '';
foreach ( $vals_args as $one_val ) {
$options .= sprintf( '<option value="%1$s">%1$s</option>', $one_val );
}
printf( '<select name="blablabla">%s</select>', $options );
}
function assign_pmpro_level_to_role($user_id, $role)
{
global $current_user;
//checks if the user doesn't have a membership level yet
if(!$current_user->user_id) {
//we found a role related to pmpro level
if($role == "customer")
{
pmpro_changeMembershipLevel(6, $user_id); //gives default customers the level 20 free registration membership
}
}
}
add_action('add_user_role', 'assign_pmpro_level_to_role', 10, 2);
$query = new WP_Query( [
'post_type' => 'fitnes_programs',
'posts_per_page' => (int)$count,
'tax_query' => [
[
'taxonomy' => 'fitnes_program',
'field' => 'id',
'terms' => [38]
]
]
] );