WP requests (запити WordPress)

Last update: 22 Квітня, 2023

Category: WordPress

get_template_directory()

Get the post by ID

global $post;
$my_query = new WP_Query('p=27');
while ($my_query->have_posts()) : $my_query->the_post();
    the_content('');
endwhile; ?>
$post = get_post( '24449' );
echo $post->post_content;

Ссылка на главную страницу в WordPress: home_url()

По умолчанию возвращает url главной страницы без слэша (/) в конце. Учитывает текущий язык, выбранный в WPML и SSL-соединение.

Как работает:

echo home_url();    // http://example.com
echo home_url('/'); // http://example.com/ 
echo home_url('/blog', 'https'); // http://example.com/blog
echo home_url('#hash', 'https'); // http://example.com/#hash
echo home_url( 'http://foo.bar/foo' ); // https://example.com/http://foo.bar/foo