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

Is it possible to use the_post 2 times in one loop

Yes, but not by calling the_post twice in a loop. Instead, use 2 loops and rewind_posts. The first loop displays column1 and skips even posts. Then you call rewind_posts() to go back to the beginning. The second loop displays column2 and skips odd posts. After the first loop, call rewind_posts(); and it will rewind the … Read more

Custom fields disappearing when a custom post type is assigned

I ended up solving this on my own and thought I would come back to show my solution. On my taxonomy page I needed to get the current taxonomy term like so: <?php $term = get_queried_object(); if (get_field(‘subtitle’, $term)) { ?> <p><?php the_field( ‘subtitle’, $term )?></p> <?php } ?> Here is the documentation page: https://www.advancedcustomfields.com/resources/adding-fields-taxonomy-term/

WordPress duplicating posts from single loop

Unless I’ve mis-interpreted what you are trying to accomplish, you added the foreach loop and you don’t need it. Having it run while inside a while loop seems to be duplicating your intentions. Remove the foreach loop altogether, delete the first wp_reset_postdata();, and un-comment the 2nd one: <div id=”carouselTestimonial” class=”carousel slide” data-bs-ride=”carousel”> <div class=”carousel-inner”> <?php … Read more