Finding the next 5 posts

The integral part is using a date_query in a custom WP_Query to fetch the adjacent posts according to the parameters passed to it. Here is an idea coming from a plugin I’m busy with To accomplish what you need, you’ll need the following The current post object to get the post_date and ID The categories … Read more

is_archive() doesn’t work on public query var archive pages?

Try this: add_action( ‘template_redirect’, ‘my_test_if_archive’ ); function my_test_if_archive() { global $wp_query; $qv = array_keys( $wp_query->query ); $archives = array(‘year’, ‘monthnum’, ‘day’, ‘w’, ‘m’, ‘author’, ‘post_type’); $is_archive = ! empty( array_intersect( $qv, $archives ) ); $is_tax = ! empty( $wp_query->tax_query->queries ); if ( $is_archive || $is_tax ) { // this is an archive } }

WordPress Search Filter Only for Page with Child of Child of Child of Child of Child

You can probably do something like this. It’s probably less efficient, but should find all descendants of a given page rather than just direct children. function find_descendants($post_id) { $descendant_ids = array(); $pages = get_pages(“child_of=$post_id”); foreach ($pages as $page) { array_push($descendant_ids, $page->ID); } return $descendant_ids; } function SearchFilter($query) { if ($query->is_search) { $query->set ( ‘post__in’, find_descendants(21) … Read more

Create subpage /user/ or /my-profile/ like /author/ with additional query like /user/user123

If I understand you well, you can do that with add_rewrite_rule(); function to map the url to specific query variables. https://codex.wordpress.org/Rewrite_API/add_rewrite_rule function myfunc_rewrite_rules() { add_rewrite_rule(‘user/?([^/]*)’, ‘index.php?pagename=user&username=$matches[1]’, ‘top’); } function myfunc_username_query_vars($vars) { $vars[] = ‘username’; return $vars; } add_action(‘init’, ‘myfunc_rewrite_rules’); //add query vars (username) to wordpress add_filter(‘query_vars’, ‘myfunc_username_query_vars’); function myfunc_display() { $userpage = get_query_var(‘pagename’); $username = … Read more

Query by 2 values of a repeater ACF field

I know this is an old question, but I thought I’d post the answer in case anybody else is facing the same problem. functions.php: function add_cond_to_where( $where ) { //Replace showings_$ with repeater_slug_$ $where = str_replace(“meta_key = ‘showings_$”, “meta_key LIKE ‘showings_%”, $where); return $where; } add_filter(‘posts_where’, ‘add_cond_to_where’); Query: //Replace showings_$ with repeater_slug_$ //Replace _discounts with … Read more

$query->query_var[‘post_type’] not set for pages

To clear up some confusion in previous answers, pre_get_posts isn’t a filter so you don’t need to return anything. Your only problem that I see is the if: if ( !is_search() && !in_array( get_post_type(), $post_types ) ) return; Basically get_post_type() is going to return false during pre_get_posts because the global $post hasn’t been set yet … Read more

Custom Query to search through categories

It sounds like you’re looking for the get_terms() function that’s a wrapper for WP_Term_Query. There you can e.g. use the name__like, description__like or search parameters. Example: Here’s what kind of WHERE query they generate: ‘name__like’ => ‘hout’ >>> (t.name LIKE ‘%hout%’) ‘description__like’ => ‘hout’ >>> tt.description LIKE ‘%hout%’ ‘search’ => ‘hout’ >>> (t.name LIKE ‘%hout%’) … Read more

Can’t pass table to $wpdb->prepare

The prepare() method escapes %s. The second piece of code you listed breaks because quotation marks are added to the table name, hence it doesn’t match what’s in the DB. The first piece of code works because it’s a straight string replacement hence matching the name of the table in the database. What is the … Read more

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