Skip to content

Instantly share code, notes, and snippets.

@AnatoliyAkhmatov
Last active May 8, 2018 09:48
Show Gist options
  • Save AnatoliyAkhmatov/efa66984580bb39e3c0499ae59b86ccd to your computer and use it in GitHub Desktop.
Save AnatoliyAkhmatov/efa66984580bb39e3c0499ae59b86ccd to your computer and use it in GitHub Desktop.
$posts = get_posts([ 'category_name' => 'about_features', // slug или name категории
'numberposts' => '-1' ]); // кол-во постов -1 без лимита, 0 лимит заданный в админке
function post_by_slug($posts, $slug) {
for ($x = 0, $len = count( $posts ); $x < $len; $x++) {
if ($posts[$x]->post_name == $slug) {
return $posts[$x];
}
}
return false;
}
$post = post_by_slug( $posts, 'about_quote' ); // обязательно использовать глобальую переменную $post
if ($post): setup_postdata( $post ); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment