WordPress website links redirect to homepage

Go into Admin, Settings, Permalinks, and change whatever is there to another choice. Save the setting. Then go back and change it to what you want it to be. Save the setting. Then try going to a page on your site. Also, check that your htaccess file has the basic WordPress settings. See here: https://wordpress.org/support/article/htaccess/

Custom post archive with search, is_search() is false?

Name your keyword input just s <input name=”s” type=”text” placeholder=”Filter by keyword” value=””/> This is enough for WP to recognize the request as search plus you won’t have to do the $query->set( ‘s’, … ) later In pre_get_posts action use the conditional is_post_type_archive( ‘document’ ) so your if statement look something like this: if ( … Read more

How to account for empty key values in wp_query?

how do I include those posts that don’t have an entry? You can include those posts (which do not have the expire_date field/meta) by adding a second clause with ‘compare’ => ‘NOT EXISTS’, and then set the relation to OR: $query_args[‘meta_query’] = array( // the relation between the root clauses/queries; defaults to AND ‘relation’ => … Read more

$_GET vs get_query_var()

get_query_var() gets variables from the main instance of WP_Query. It’s the equivalent of running global $wp_query; $wp_query->get( ‘posts_per_page’ ); It is not directly related to $_GET in any way. However, WordPress has a list of ‘public’ query variables that will be applied to the main query if they are passed as URL parameters. This is … Read more

Pre_get_post on CPT archive page

pre_get_posts filters run before WordPress has figured out the main query, which is used to pick the template. For this reason you can’t put it inside the template, it has to run before the template is picked, not afterwards. For this reason, it has to go inside your themes function.php or in a plugin

Get access to all terms associated to each post that the wp_query loop displays

If I understood you correctly, you are looking for get_the_terms(), which.. Retrieves the terms of the taxonomy that are attached to the post. You could for example have helper functions like these, // functions.php function my_sports_post_terms( int $post_id ) : array { $taxonomies = [‘basketball’, ‘volleyball’, ‘baseball’]; $terms = []; foreach ($taxonomies as $taxonomy) { … Read more