Pagination not working past page 3 on archive page of category

I had a similar issue and maybe this is also helpful when pagination is only working sometimes: e.g. /page/1/ and /page/2/ are working and /page/3/ not. Result: Error 404. Problem is: default value (12 items each page) for posts_per_page (WordPress Settings/Reading) is loaded always from database before the template is loaded. So $args=[‘posts_per_page’ => 1] … Read more

How to show only specific category post by user role without plugin and restrict all other cats

If you’re using global loop for displaying the posts, then you can easily modify which posts are shown using pre_get_posts action. function restrict_categories_for_user( $query ) { if ( ! is_admin() && $query->is_main_query() && get_current_user_id() ) { $user = wp_get_current_user(); if ( in_array( ‘viewer_a’, (array) $user->roles ) ) { // The user has the “viewer_a” role … Read more

WordPress meta query not working

When using LIKE clause, you should be using % to the start and end of the value to make it match with the existing values. So your query should look like this. add_action( ‘pre_get_posts’ , ‘my_pre_get_posts’ ); function my_pre_get_posts( $query ) { $value=”%”.$_GET[‘s’].’%’; if( $query->is_main_query() && $query->is_search() ) { $query->set( ‘meta_query’, array( array( ‘key’ => … Read more

How can I re-query post_type and rewrite the url?

I think you need to first define property_com_listing_type as a query: https://codepen.io/the_ruther4d/post/custom-query-string-vars-in-wordpress Then you can rewrite the urls with add_rewrite_rule (do not forget to save permalinks after change): https://codex.wordpress.org/Rewrite_API/add_rewrite_rule with a regex like ^category/([^/]+)/([^/]+)/? Then you can modify the query using pre_get_posts: https://developer.wordpress.org/reference/hooks/pre_get_posts/

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