Query by “similar” post title

You can use either search parameter of wp_query : Code $args = array(“post_type” => “mytype”, “s” => $title); $query = get_posts( $args ); Or you can get posts based on title throught wpdb class: global $wpdb; $myposts = $wpdb->get_results( $wpdb->prepare(“SELECT * FROM $wpdb->posts WHERE post_title LIKE ‘%s'”, ‘%’. $wpdb->esc_like( $title ) .’%’) ); Than you’ll … Read more

How do I show related posts from categories instead of tags?

In the function wp_get_post_terms() you can select the taxonomy. the default is post_tag you can change it to category. And in the WP_Query args you need to change the tag__in to category__in. // get the categories $categories = wp_get_post_terms($post->ID, ‘category’); if ($categories) { $categories_ids = array(); foreach($categories as $individual_cat) $categories_ids[] = $individual_cat->term_id; $args=array( ‘category__in’ => … Read more

Paginate_Links page 2 doesn’t work

I believe the mistake is using get_query_var( ‘paged’ ): this comes from the main query, not from your custom query. Try this (untested): $current_page = 1; if ( isset( $_GET[‘page’] ) ) { $current_page = absint( $_GET[‘page’] ); } And then replace uses of get_query_var( ‘paged’ ) with $current_page.

get_posts() function does not honor correct post type

This could be caused by a pre_get_posts action that doesn’t have the proper conditions/checks. For example: add_action( ‘pre_get_posts’, function( $query ) : void { if ( is_post_type_archive( ‘tribe_events’ ) ) { $query->set( ‘post_type’, ‘tribe_events’ ); } } ); Likewise if this was a page template and not a post archive they might have this in … Read more

WP Query order posts not working

To sort by title in ascending order (alphabetical order), you can use orderby => title and order => ASC: $args = array( ‘post_type’ => ‘marketing_en’, ‘orderby’ => ‘title’, ‘order’ => ‘ASC’, ‘tax_query’ => array( array( ‘taxonomy’ => ‘custom_post_type’, ‘field’ => ‘slug’, ‘terms’ => array(ICL_LANGUAGE_CODE == ‘ar’ ? ‘tool-ar’ : ‘tool’), ), ), ); $loop = … Read more

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