WP_Query Search is not working.....for keyword 'TATTOO' - wordpress

This search is not working.... Any guess?? This is a very simple piece of code.
It is for showing records related with keyword tattoo for title field. It shows all products. The search is not triggered.
$args = array(
'posts_per_page' => $per_page,
'offset' => $paged,
'post_type' => 'product',
'meta_key' => $orderby,
'orderby' => $num_orderby,
'order' => $order,
'search' => '*tattoo*',
'search_columns' => array('post_title')
);
$new_query = new WP_Query( $args );`

http://codex.wordpress.org/Class_Reference/WP_Query#Search_Parameter
try use 's' instead 'search'
...
's' => '*tattoo*',
...

Related

Use 'LIKE %word%' for ACF Query Wordpress

I use ACF plugin on my wordpress site and I want to code custom research.
I have many products and I want to display products which contain the searched word.
I do my query like this :
$args = array(
'post_type' => 'product',
'meta_key' => 'brand',
'meta_value' => $word,
'compare' => 'LIKE');
$the_query = new WP_Query($args);
But this display only products with the brand which exactly matches with $word.
for exemple if I search "yan" I want to display products with the brand "YANMAR", "POLYAN", "TRYANPO", etc.
How to do this please ?
Thank you and have a good day !
Try below code.
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'posts_per_page' => -1,
'meta_query' => array(
array(
'key' => 'brand',
'value' => $word,
'compare' => 'LIKE'
)
)
);
$the_query = new WP_Query($args);

WP_Query with “post_title LIKE 'something%'” and category

I need to do a WP_Query with a LIKE on the post_title and category
This query_post is not working
query_posts(
array(
'post_type' => 'add_buying',
'like' => $keywords,
'posts_per_page' => 5,
'taxonomy' => 'add_country',
'term' => 'drawing'
));
Check this url and change the like parameter.
query_posts( array(
'post_type' => 'add_buying',
's' => $keywords,
'posts_per_page' => 5,
'taxonomy' => 'add_country',
'term' => 'drawing'
));
Change your second parameter to 's' and I think it's going to work:
$args = array(
'post_type' => 'post',
's' => $search_term,
'post_status' => 'publish'
);
$wp_query = new WP_Query($args);
And good luck
title (string) - use post title (available with Version 4.4).
$args = array(
'post_type' => 'post',
'title' => $title,
'post_status' => 'publish'
);
$wp_query = new WP_Query($args);

fetch customer field on wp_posts from wordpress

I am using wordpress, I have added "city_name" to wp_posts, now i am using the following query but did not getting result according to city_name.
$query_args = array(
'post_type' => 'product',
'order' => 'DESC',
'post_status' => 'publish',
'city_name' => 'karachi',
'showposts' => 7
//'offset'=> 0,
//'posts_per_page'=>2
);
store city name in meta field using update_post_meta wordpress function
update_post_meta('post id here','city_name','karachi')
and now you can query for this field like so :
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'meta_query' => array(
array(
'key' => 'city_name',
'value' => 'karachi'
)
)
);
$query = new WP_Query($args);
Refer Here : Wp Query

To display the post order by modified date in wordpress

I have to display the posts oder by last modified date. So I used the code bellow.
$args = array(
'post_type' => $post_type,
'numberposts' => '2',
'orderby' => 'modified',
'order'=> 'ASC',
);
$the_query = new WP_Query( $args );
But I could not find any update in the above code. Should i use something else instead of 'orderby' => 'modified' in the argument.
You should use DESC for order.
Try this:
$the_query = new WP_Query( array(
'post_type' => $post_type,
'numberposts' => '2',
'orderby' => 'modified',
'order' => 'DESC',
));
Using DESC will give you the latest post first(descending order).
EDIT:
As Andrew commented, the default value for order is DESC and can thus be omitted from the code:
$the_query = new WP_Query( array(
'post_type' => $post_type,
'numberposts' => '2',
'orderby' => 'modified',
));
Try
<?php query_posts($query_string . '&post_type=$post_type&orderby=modified&order=desc'); ?>

query_posts exclude a meta key

<?php query_posts(array('showposts' => 1000, 'post_parent' => $post->ID, 'post_type' => 'page', 'orderby' => 'title', 'order' => 'ASC', 'meta_key' => featured_product, 'meta_value' => 1)); ?>
<?php query_posts(array('showposts' => 1000, 'post_parent' => $post->ID, 'post_type' => 'page', 'orderby' => 'title', 'order' => 'ASC')); ?>
I have 2 queries, first to show meta key with featured_product eq 1. So I want to exclude all the featured products on the second query. How can i do that please? Thanks!
You simply need the meta_compare for that:
<?php query_posts(
array(
'showposts' => 1000,
'post_parent' => $post->ID,
'post_type' => 'page',
'orderby' => 'title',
'order' => 'ASC',
'meta_key' => 'featured_product',
'meta_compare' => '!=',
'meta_value' => 1
)
); ?>
While looping through your first query, build an array consisting of the ids of the posts in the loop. Then use pass this array to the second query using "post__not_in" => $your_array

Resources