$action_query = new WP_Query( [
'post_type' => 'action',
'post_status' => 'publish',
] );
/**
* Изменение количества продуктов на странице
*
* @compatible WooCommerce 3.2.0 +
* @see https://github.com/woocommerce/woocommerce/blob/7701d4b57cb20dc89e25bb7bf2ff872d85f4c535/includes/class-wc-query.php#L412
*/
function loop_product_per_page( $per_page ) {
if ( ! empty( $_GET[ 'products-per-page' ] ) ) {
$per_page = (int) ( $_GET[ 'products-per-page' ] );
} else {
$per_page = 12;
}
return $per_page;
}
add_filter( 'loop_shop_per_page', 'loop_product_per_page', 9999 );
/**
* Define default terms for custom taxonomies in WordPress 3.0.1
*
* @author Michael Fields http://wordpress.mfields.org/
* @props John P. Bloch http://www.johnpbloch.com/
* @props Evan Mulins https://circlecube.com/circlecube/
*
* @since 2010-09-13
* @alter 2013-01-31
*
* @license GPLv2
*/
function mfields_set_default_object_terms( $post_id, $post ) {
if ( 'publish' === $post->post_status && $post->post_type === 'your_custom_post_type' ) {
$defaults = array(
'your_taxonomy_id' => array( 'your_term_slug' )
);
$taxonomies = get_object_taxonomies( $post->post_type );
foreach ( (array) $taxonomies as $taxonomy ) {
$terms = wp_get_post_terms( $post_id, $taxonomy );
if ( empty( $terms ) && array_key_exists( $taxonomy, $defaults ) ) {
wp_set_object_terms( $post_id, $defaults[$taxonomy], $taxonomy );
}
}
}
}
add_action( 'save_post', 'mfields_set_default_object_terms', 100, 2 );
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 ] );
}