What is the proper way to use pre_get_post?

Update From your comments, it seemed that you’re having a hard time understanding about the WordPress main query and the is_main_query() method in the WP_Query class, so hopefully the following would help clear your doubts: Please check codex.wordpress.org/Query_Overview and learn how WordPress determines what posts or pages to display on a page. The main query … Read more

Set a custom number of posts on the first page

The pre_get_posts runs before WP_Query has been setup. Some template tags and conditional functions that rely on WP_Query will not work. you will need to work directly with the query vars, which are passed to the pre_get_posts hook as an argument. See the more information on the following pages: pre_get_posts and using pre_get_posts Try using … Read more

Extend taxonomy term page with other posts

Ok I find a solution. I use posts_where filter in pre_get_posts. With this filter I can remove the term related WHERE part from the default SQL query. function custom_loops($query) { if (is_tax( ‘service_photo_location’ )){ $query->set( ‘posts_per_page’, 10); $query->set( ‘post__in’, $ids); $query->set( ‘orderby’, ‘title’); $query->set( ‘order’, ‘ASC’); add_filter( ‘posts_where’, function ( $where ) { $where = … Read more

Insert a variable in pre_get_posts

You can not use a variable inside a function which has been defined outside the function! Get the value from $_GET inside the function. function my_home_category($query) { if (isset($_GET [‘p’])) { $catvar = get_cat_ID($_GET [‘p’]); $query->set(‘cat’, $catvar); } } add_action( ‘pre_get_posts’, ‘my_home_category’ );

how to get content from other site and show it?

You can use wp_remote_get or/and wp_remote_retrieve_body functions to get HTTP response Retrieve the raw response from the HTTP request using the GET method. Results include HTTP headers and content. codex here $response = wp_remote_get( $url, $args ); Retrieves the body of an already retrieved HTTP request. Codex $the_body = wp_remote_retrieve_body( wp_remote_get(‘http://example.com’) );

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)