Hi, you can try this
function my_post_queries( $query ) {
// only homepage and is the main query
if ($query->is_home() && $query->is_main_query()){
// display only posts in category with id=32
$query->set('cat', 32);
}
}
add_action( 'pre_get_posts', 'my_post_queries' );
I tried your suggestion but get an error message probably because of the above bit of codding, can you advise me how to write properly the following or maybe how to merge this two in one :
[ Moderator Note: Please post code or markup snippets between backticks or use the code button not blockqoute. ]
function my_post_queries( $query ) {
// not an admin page and is the main query
if (!is_admin() && $query->is_main_query()){
if(is_home()){
$query->set('post__not_in', get_option( 'sticky_posts' ) );
}
}
}
add_action( 'pre_get_posts', 'my_post_queries' );
function my_post_queries( $query ) {
// only homepage and is the main query
if ($query->is_home() && $query->is_main_query()){
// display only posts in category with id=32
$query->set('cat', 32);
}
}
add_action( 'pre_get_posts', 'my_post_queries' );
as mentioned above the first part is to avoid sticky post appearing on home page (only appear in slider) and the second part is your suggestion … thanks for your help …
Hi, you are using two functions with the same name – hence you get an error.
use this instead:
function my_post_queries( $query ) {
// only homepage and is the main query
if ($query->is_home() && $query->is_main_query()){
// display only posts in category with id=32
$query->set('cat', 32);
// avoid sticky posts
$query->set('post__not_in', get_option( 'sticky_posts' ) );
}
}
add_action( 'pre_get_posts', 'my_post_queries' );
where you have to change the value 32 to match your category id.
works perfectly, thanks … I have another question but will make a new post for that … see you, and thanks again …