query_posts,
он повторно запускает запросы в базу и переопределяет глобальный объект WP_Query
. Из офф. документации:Note: This function will completely override the main query and isn’t intended for use by plugins or themes. Its overly-simplistic approach to modifying the main query can be problematic and should be avoided wherever possible. In most cases, there are better, more performant options for modifying the main query such as via the ‘pre_get_posts’ action within WP_Query.
get_posts или pre_get_posts
- Это обертка WP_Query
, которая упрощает выборку постов и не изменят глобальные переменные, в ней еще определены некоторые дефолтные аргументы из-за чего выборку сделать проще.WP_Query
<?php
$variable = wp_list_categories('echo=0&show_count=1&title_li=<h3>Рубрики</h3>');
$variable = str_replace(array('(',')'), '', $variable);
echo $variable;
?>
function smart_category_top_parent_id ($catid) {
while ($catid) {
$cat = get_category($catid); // get the object for the catid
$catid = $cat->category_parent; // assign parent ID (if exists) to $catid
// the while loop will continue whilst there is a $catid
// when there is no longer a parent $catid will be NULL so we can assign our $catParent
$catParent = $cat->cat_ID;
}
return $catParent;
}
$category = get_the_category($post->ID); //post id
$catid = $category[0]->cat_ID;
$top_level_cat = smart_category_top_parent_id ($catid);
<?php
/*
Template Name: Email Send
*/
$adminemail="example@mail.com";
$date=date("d.m.y");
$time=date("H:i");
$name=$_POST['name'];
$ephone=$_POST['ephone'];
$question=$_POST['question'];
....