add_action( 'template_redirect', 'my_checkout_redirect' );
function my_checkout_redirect() {
global $wp;
if ( is_checkout() && ! empty( $wp->query_vars['order-received'] ) ) {
wp_redirect( '%my_custom_url%' );
exit;
}
}
$array = array('post_type' = > 'product',
'tax_query' = array(
array(
'taxonomy' => 'product_cat',
'field' = > 'term_id/slug/name ',
'terms' = 'id/slug/name'
)
)
);
if( wp_is_mobile() ) {
echo 'бла бла бла' // бла бла бла будет видно только на мобильных девайсах
}
<form role="search" method="get" id="searchform" action="<?php echo home_url( '/' ) ?>" >
<label class="screen-reader-text" for="s">Поиск: </label>
<input type="text" value="<?php echo get_search_query() ?>" name="s" id="s" />
<input type="submit" id="searchsubmit" value="найти" />
</form>
/**
* Замена директории для загрузки
*/
function edd_set_upload_dir( $upload ) {
$upload['subdir'] = '/video';
$upload['path'] = $upload['basedir'] . $upload['subdir'];
$upload['url'] = $upload['baseurl'] . $upload['subdir'];
return $upload;
}
// меняем директорию
add_filter( 'upload_dir', 'edd_set_upload_dir' );
//грузим файл
$video_id = media_handle_upload( 'video-file',$post_id );
// возвращаем директорию на дефолтную
remove_filter( 'upload_dir', 'edd_set_upload_dir' );
define('INST_USER_ID','xxxxxxxxxxxx');
define('INST_CLIENT_ID','xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx);
$json = file_get_contents("https://api.instagram.com/v1/users/{INST_USER_ID}/media/recent/?client_id={NST_CLIENT_ID}");
$array = json_decode($json);
header('Content-Type: text/html; charset= utf-8');
$file = $_SERVER['DOCUMENT_ROOT']. 'instagram-log.txt';
$old = file_get_contents($file);
$old_array = explode('\n',$old);
foreach ($array->data as $one){
if ( in_array($one->images->standard_resolution->url, $old_array ) === false ) {
$fp = fopen($file, 'a+');
fwrite($fp, $one->images->standard_resolution->url.'\n');
fclose($fp);
$post_data = array(
'post_title' => $one->caption->text,
'post_content' => '',
'post_status' => 'draft',
'post_author' => 1,
'post_category' => array( 1,2,3,4,5,6 )
);
$post_id = wp_insert_post( $post_data );
$url = $one->images->standard_resolution->url;
require_once(ABSPATH . "wp-admin" . '/includes/image.php');
require_once(ABSPATH . "wp-admin" . '/includes/file.php');
require_once(ABSPATH . "wp-admin" . '/includes/media.php');
$desc = "";
$file_array = array();
$tmp = download_url( $url );
preg_match('/[^\?]+\.(jpg|jpe|jpeg|gif|png)/i', $url, $matches );
$file_array['name'] = basename( $matches[0] );
$file_array['tmp_name'] = $tmp;
$id = media_handle_sideload( $file_array, $post_id, $desc );
if( is_wp_error( $id ) ) {
@unlink($file_array['tmp_name']);
return $id->get_error_messages();
}
@unlink( $file_array['tmp_name'] );
update_post_meta( $post_id, '_thumbnail_id', $id );
$image_attributes = wp_get_attachment_image_src( $id );
$my_post = array();
$my_post['ID'] = $id;
$my_post['post_content'] ='<img src="' . $image_attributes[0] . '" alt=""/>';
wp_update_post( $my_post );
wp_publish_post( $post_id );
}
}
global $woocommerce;
if ( isset( $woocommerce->session ) )
$woocommerce->session->'name' = 'value';
global $woocommerce;
if ( isset( $woocommerce->session ) && isset( $woocommerce->session->'name' ) )
$name_velue = $woocommerce->session->'name';
global $woocommerce;
if ( isset( $woocommerce->session ) )
unset( $woocommerce->session->'name' );
<?php add_action('admin_footer', 'my_action_javascript');
function my_action_javascript() {
?>
<script type="text/javascript" >
jQuery('#btn').click(function () {
jQuery.post(ajaxurl, { 'action': 'my_action'}, function(data) {
jQuery('#primer').html(data);
});
})
</script>
<?php
}
add_action('wp_ajax_my_action', 'my_action_callback');
function my_action_callback() {
echo 'ivan';
wp_die();
}
?>
// добавление опции на страницу "Настройки постоянных ссылок"
add_action( 'load-options-permalink.php', 'custom_load_permalinks' );
function custom_load_permalinks() {
if( isset( $_POST['my_post_base'] ) ) {
update_option( 'my_post_base', sanitize_title_with_dashes( $_POST['my_post_base'] ) );
}
add_settings_field( 'my_post_base', __( 'CPT Base' ), 'my_post_base_callback', 'permalink', 'optional' );
}
function my_post_base_callback() {
$value = get_option( 'my_post_base' );
echo '<input type="text" value="' . esc_attr( $value ) . '" name="my_post_base" id="my_post_base" class="regular-text" />';
}
// в массив параметров для register_post_type необходимо добавить
'rewrite' => array( 'slug' => get_option( 'my_post_base' ) )
<?php
$array = array(
'post_type' => 'post_type',
'tax_query' => array(
array(
'taxonomy' = 'taxonomy',
'field' => 'id',
'terms' => array( 1, 2, 3 ),
)
)
);
$query = new WP_Query;
$my_query = $query->query($array );
foreach( $my_query as $post ){
update_post_meta($post->ID, 'key', 'value');
}