register_taxonomy()
, лучше для каждого типа записи иметь свои таксономии, так вы избежите множества проблем в дальнейшем$post_type = get_post_type();
if ( file_exists( get_theme_file_path( 'templates/archive/archive-' . $post_type . '.php' ) ) ) {
get_template_part( 'templates/archive/archive-' . $post_type );
} else {
get_template_part( 'templates/archive/archive-common' );
}
register_post_type()
тоже есть аргумент rewrite, который тоже используется для построения ссылок$args = [
'post_type' => ['post','service'],
'post__in' => [5,12,2,14,7],
'orderby' => 'post__in',
];
$loop = new WP_Query( $args );
if ( get_post_type() === 'service' ) {
get_template_part( 'templates/archive/archive-service' );
} else {
get_template_part( 'templates/archive/archive-common' );
}
$post_type = get_post_type();
if ( file_exists( get_theme_file_path( 'templates/archive/archive-' . $post_type . '.php' ) ) ) {
get_template_part( 'templates/archive/archive-' . $post_type );
} else {
get_template_part( 'templates/archive/archive-common' );
}
add_filter( 'post_gallery', 'my_gallery_shortcode', 10, 3 );
function my_gallery_shortcode( $output = '', $atts = null, $instance = null ) {
$return = $output; // fallback
// retrieve content of your own gallery function
$my_result = get_my_gallery_content( $atts );
// boolean false = empty, see http://php.net/empty
if( !empty( $my_result ) ) {
$return = $my_result;
}
return $return;
}
wp_query()
получить то, что вы хотите нельзя и придется писать SQL запросsave_post
или wp_insert_post()
вешаю проверку нужного условия и добавляю мету с ключом _type$post_slug = get_post_field( 'post_name', get_post_ID() );
if ( stripos( $post_slug, 'doc_class_' ) !== false ) {
add_post_meta( $post_id, '_type', 'doc_class', true );
}
add_action( 'wp_enqueue_scripts', 'theme_scripts' );
function theme_scripts() {
wp_enqueue_style( 'theme-style', get_stylesheet_uri(), array(), filemtime( get_theme_file_path( '/style.css' ) ) );
}
get_stylesheet_uri()
получит ссылку на стили дочерней темы, а не родительской<form method="get" class="obj-filter">
<input class="obj-filter-input" type="radio" id="light" name="color" value="light">
<label class="obj-filter-label" for="light">Light</label>
<input class="obj-filter-input" type="radio" id="dark" name="color" value="dark">
<label class="obj-filter-label" for="dark">Dark</label>
<input id="obj-filter-submit" type="submit" class="button" value="Фильтровать">
</form>
add_filter( 'query_vars', 'add_query_vars' );
function add_query_vars( $qvars ) {
$qvars[] = 'color';
return $qvars;
}
add_action( 'pre_get_posts', 'custom_pre_get_posts', 1 );
function custom_pre_get_posts( $query ) {
// Выходим, если это админ-панель или не основной запрос
if( is_admin() || !$query->is_main_query() )
return;
// сортируем записи 'obj', если указан гет-запрос
if ( $query->is_archive() && $query->get('post_type') === 'obj' ) {
if ( $var = get_query_var( 'color', false ) ) {
$query->set( 'obj-cat', $var );
}
}
}