add_filter( 'the_title', 'f711_title_filter' );
function f711_title_filter( $title ) {
return str_replace( '2020', '2021', $title );
}
get_posts()
и в цикле обновить с помощью wp_update_post()
To change the location of your Theme Options page, you use set_page_parent($parent), where $parent is either:
- Title of a top level Theme Options page.
- Indentificator of a top level menu section in the admin menu sidebar. This corresponds to the $parent_slug parameter of add_submenu_page(). You can see all predefined page parents here.
__()
, _e()
, esc_html__()
и esc_html_e()
на английском и переводить тему с помощью loco translate или poedit <?php
/**
* The template for displaying archive pages
*
* Used to display archive-type pages if nothing more specific matches a query.
* For example, puts together date-based pages if no date.php file exists.
*
* If you'd like to further customize these archive views, you may create a
* new template file for each one. For example, tag.php (Tag archives),
* category.php (Category archives), author.php (Author archives), etc.
*
* @link https://developer.wordpress.org/themes/basics/template-hierarchy/
*
* @package WordPress
* @subpackage Twenty_Sixteen
* @since Twenty Sixteen 1.0
*/
get_header(); ?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php if ( have_posts() ) : ?>
<header class="page-header">
<?php
the_archive_title( '<h1 class="page-title">', '</h1>' );
the_archive_description( '<div class="taxonomy-description">', '</div>' );
?>
</header><!-- .page-header -->
<?php
// Start the loop.
while ( have_posts() ) :
the_post();
/*
* Include the Post-Format-specific template for the content.
* If you want to override this in a child theme, then include a file
* called content-___.php (where ___ is the Post Format name) and that
* will be used instead.
*/
get_template_part( 'template-parts/content', get_post_format() );
// End the loop.
endwhile;
// Previous/next page navigation.
the_posts_pagination(
array(
'prev_text' => __( 'Previous page', 'twentysixteen' ),
'next_text' => __( 'Next page', 'twentysixteen' ),
'before_page_number' => '<span class="meta-nav screen-reader-text">' . __( 'Page', 'twentysixteen' ) . ' </span>',
)
);
// If no content, include the "No posts found" template.
else :
get_template_part( 'template-parts/content', 'none' );
endif;
?>
</main><!-- .site-main -->
</div><!-- .content-area -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
add_filter( 'query_vars', 'add_query_vars' );
function add_query_vars( $qvars ) {
$qvars[] = 'brand';
$qvars[] = 'model';
$qvars[] = 'price';
$qvars[] = 'location';
return $qvars;
}
<form method="get" class="block obj-filter">
<div class="row d-flex align-items-center">
<div class="col-12 col-md-6 col-lg-3 col-margin-bottom-small col-lg-margin-bottom-none">
<select name="brand" id="brand" class="obj-select">
<option value="audi">Audi</option>
<option value="volkswagen">Volkswagen</option>
<option value="mercedes">Mercedes</option>
<option value="bmw">BMW</option>
</select>
</div>
<div class="col-12 col-md-6 col-lg-3 col-margin-bottom-small col-lg-margin-bottom-none">
<select name="price" id="price" class="obj-select">
<option value="20">$20 000</option>
<option value="50">$50 000</option>
<option value="75">$75 000</option>
<option value="100">$100 000</option>
</select>
</div>
<div class="col-12 col-md-6 col-lg-3 col-margin-bottom-small col-lg-margin-bottom-none">
<input type="text" name="location" id="location" class="obj-filter-input" value="">
</div>
<div class="col-12 col-md-6 col-lg-3 col-margin-bottom-small col-lg-margin-bottom-none">
<input id="obj-filter-submit" type="submit" class="button" value="Фильтровать">
</div>
</div>
</form>
https://example.loc/?brand=audi&price=50
. На хуке pre_get_posts
можно поправить основной запрос вытянув данные из гет-параметров. Вам нужно установить новые tax_query или meta_query в зависимости от логики сайтаadd_action( 'pre_get_posts', 'custom_pre_get_posts', 1 );
function custom_pre_get_posts( $query ) {
// Выходим, если это админ-панель или не основной запрос
if( is_admin() || ! $query->is_main_query() )
return;
// предположим, что это таксономия с машинами
if ( $query->is_tax( 'cars' ) ) {
$meta = array();
$meta['meta_query']['relation'] = 'AND';
// выбираем записи с GET запросами
$query_vars = ['brand', 'model', 'price', 'location'];
foreach ( $query_vars as $key => $query_var ) {
if ( $var = get_query_var( $query_var, false ) ) {
// тут пишем логику по которой собирается переменная meta_query и/или tax_query
}
}
$query->set( 'meta_query', $meta );
}
}
wp_query()
и выводите так, как вам нужно// задаем нужные нам критерии выборки данных из БД
$args = array(
'post_type' => 'page',
'post_parent' => $pageN
);
$query = new WP_Query( $args );
// Цикл
if ( $query->have_posts() ) {
echo '<ul>';
while ( $query->have_posts() ) {
$query->the_post();
echo '<li>' . get_the_title() . '</li>';
}
echo '</ul>';
} else {
// Постов не найдено
}
// Возвращаем оригинальные данные поста. Сбрасываем $post.
wp_reset_postdata();
pre_get_posts
add_action( 'pre_get_posts', 'custom_pre_get_posts', 1 );
function custom_pre_get_posts( $query ) {
// Выходим, если это админ-панель или не основной запрос
if( is_admin() || !$query->is_main_query() )
return;
// устанавливаем по 12 постов на страницах пагинации с главной
if ( $query->is_main_query() && $query->is_home() && $query->is_paged() ) {
$query->set( 'posts_per_page', 12 );
}
}
add_filter( 'query_vars', 'add_query_vars' );
function add_query_vars( $qvars ) {
$qvars[] = 'ref';
return $qvars;
}
https://example.ru/?ref=48
function set_new_cookie() {
if ( $ref = get_query_var( 'ref', false ) ) {
//setting your cookies there
}
}
add_action( 'init', 'set_new_cookie' );
add_action( 'user_register', 'referral_registration_save', 10, 1 );
function referral_registration_save( $user_id ) {
if ( isset( $_COOKIE['ref'] ) )
add_user_meta( $user_id, 'ref', $_COOKIE['ref'], true );
}
get_template_part()
if ( in_category( 'news' ) ) {
get_template_part( 'templates/single', 'news' );
} elseif( in_category( 'articles' ) ) {
get_template_part( 'templates/single', 'articles' );
} else {
get_template_part( 'templates/single', 'default' );
}
wp_add_inline_script()
add_action('wp_enqueue_scripts', function() {
wp_enqueue_script( 'my_scripts', get_stylesheet_directory_uri() .'/my_scripts.js' );
wp_add_inline_script( 'my_scripts', '$(\'.selectpicker\').selectpicker();' );
});
/* Получим в HTML коде
<script type='text/javascript' src='http://example.com/wp-content/themes/mytheme/my_scripts.js'></script>
<script type='text/javascript'>
$('.selectpicker').selectpicker();
</script>
*/
$categories = get_the_terms( $post->ID, 'voprosy-types' );
$category_ids = array();
foreach( $categories as $individual_category ) {
$category_ids[] = $individual_category->term_id;
}
$args = array(
'post__not_in' => array( $post->ID ),
'posts_per_page' => '5',
'orderby' => 'rand',
'tax_query' => [
[
'taxonomy' => 'voprosy-types',
'field' => 'id',
'terms' => $category_ids,
]
]
);
$locale = get_locale();
if( $locale == 'uk' ) {
echo do_shortcode( '[contact-form-7 id="420" title="Оформити заявку"]' );
} elseif( $locale == 'ru_RU' ) {
echo do_shortcode( '[contact-form-7 id="419" title="Оформить заявку"]' );
} else {
echo do_shortcode( '[contact-form-7 id="421" title="Make a request"]' );
}
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, который тоже используется для построения ссылок