<?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');
}
function wtf_this(){
foreach ( debug_backtrace() as $called_file ) {
foreach ( $called_file as $index ) {
if ( !is_array($index[0]) AND strstr($index[0],'/themes/') AND !strstr($index[0],'footer.php') ) {
$template_file = $index[0] ;
}
}
}
$template_contents = file_get_contents($template_file) ;
preg_match_all("see:(.*)\n)siU",$template_contents,$template_name);
$template_name = trim($template_name[1][0]);
if ( !$template_name ) { $template_name = '(default)' ; }
$template_file = array_pop(explode('/themes/', basename($template_file)));
echo $template_file . ' -> '. $template_name ;
}
// обычно цепляю сюда
add_action('get_header','wtf_this',200);
function custom_shortcode_scripts() {
global $post;
if( is_a( $post, 'WP_Post' ) && has_shortcode( $post->post_content, 'custom-shortcode') ) {
wp_enqueue_script( 'custom-script');
}
}
add_action( 'wp_enqueue_scripts', 'custom_shortcode_scripts');
jQuery(function($){
$(document).ready(function(){
function test(){
if( ! $( ".office-accordion" ).length ) return false;
$( ".office-accordion" ).accordion({heightStyle: "content"});
}
test();
});
});