Get posts by similar names and categories
Get posts by similar names and categories
Get posts by similar names and categories
After searching through two dozen blog posts I was able to combined several approaches and make this work. function my_search_by_title_only( $search, $wp_query ) { if ( ! empty( $search ) && ! empty( $wp_query->query_vars[‘search_terms’] ) ) { global $wpdb; $q = $wp_query->query_vars; $n = ! empty( $q[‘exact’] ) ? ” : ‘%’; $search = array(); … Read more
Follow the example code below, if you are using WordPress default post. For custom post type the query will be different. <?php $args = array( ‘category_name’ => ‘parent_category_slug+featured_category_slug’, // change the category slug as your own ); $query = new WP_Query($args); if($query->have_posts()): while($query->have_posts()): $query->the_post(); ?> <h4><?php the_title(); ?></h4> <?php endwhile; // main loop wp_reset_postdata(); endif; … Read more
“’orderby’ => $company_name,” should be “’orderby’ => ‘meta_value’,“ If the value of _company_name is numeric – it should be meta_value_num. Note that ‘orderby’ can only have a predefined value and ordering does it alphabetical See the possible values at the WP_Query orderby parameter: https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters The ordering parameter says: Order alphabetical by the values of meta_key … Read more
Try this: <?php $paged = ( get_query_var( ‘paged’ ) ) ? get_query_var(‘paged’) : 1; $cat_id = 42; $child_categories=get_categories( array( ‘parent’ => $cat_id ) ); foreach ( $child_categories as $child ) { ?> <!– loop through child categories and make columns –> <div class=”col-sm-4″> <!– category title –> <?php $string = $child->cat_name; $className = str_replace(‘ ‘, … Read more
Answering my own question seems weird, but here is how I was able to achieve it – function filter_posts_by_id($query) { if ( !is_admin() && is_post_type_archive(‘CPT_NAME’) && $query->is_main_query()) { $post_ids = $_GET[‘post_ids’]; if(!empty($post_ids)) { $pids = explode(‘,’,$_GET[‘post_ids’]); $query->set(‘post__in’, $pids); } } } add_action(‘pre_get_posts’, ‘filter_posts_by_id’); PHP’s predefined variable $_GET[‘parameter’] to get the query string PHP’s explode() to … Read more
WP Query for Multiple Post Types
display the children of the post using the current page as the main parent
EDIT : Sorry just read that you need a ‘OR’ in your query. I will update anwser soon. According to your question, you can try this code. // WP_Query arguments $args = array( ‘name’ => ‘test’, ‘author_name’ => ‘test’, ); // The Query $query = new WP_Query( $args ); // The Loop if ( $query->have_posts() … Read more
Disregard. I had a DIV imbalance somewhere in there. Rebuilt it , adding one thing at a time, and cant reproduce the error.