I want to get data in wp Api using search keyword - wordpress

I want to get data in wpApi in url i am using search like this
https://www.digitemb.com/wp-json/wp/v2/posts?_embed&?filter[order]=DESC&filter[posts_per_page]=5&search=digitize&page=1
My Question is that How do i get posts data from specific categories. i don't want to get data of all categories i use this logic to
search(keyword,id){
return this.http.get("https://www.digitemb.com/wp-json/wp/v2/posts?_embed&?filter[order]=DESC&filter[posts_per_page]=5&search=" + keyword + "&page="+id)
.map(data => data.json());
}
but this data can get all categories i want specific categories posts !

Use the ID of the category to get back all posts from that category.
http://www.example.com/wp-json/wp/v2/posts?categories=category-ID
List of available arguments - https://developer.wordpress.org/rest-api/reference/posts/#arguments

Related

how to get list of admin column name in wordpress

I am developing a custom WordPress plugin so I need to retrieve the list of all column in to my plugin file can anyone help me to how I get the list of below column.
in my case how I get list like.
I need a list like
author, title, Tags, categories, Date, Short code

Algolia for WooCommerce - Filter only through titles in the autocomplete

I'm trying to filter the autocomplete results in Algolia (in Woocommerce) by "post_title" only.
I have modified the template in child-theme/algolia/autocomplete.php :
attributesToSnippet: [
'content:10'
],
by
attributesToSnippet: [
'post_title'
],
but it doesn't work, I have irrelevant results, as shown : https://imgur.com/a/9dEv7bI
How can I achieve the desired result ? Thank you.
My understanding is that you would like Algolia only to return results by searching into the post titles.
The attributesToSnippet asks the engine to return a relevant snippet of a given size for a given attribute that matched the query. However in your case, this is not what you will want to change in order to only have the search operate on post titles.
Instead you should be changing the searchableAttributes.
You can do so by heading into your Algolia dashboard, going to the Indices tab and select your index. Then head to the Ranking tab and remove the attributes you don't want the engine to search on.
By only leaving the post_title in the searchable attributes, your autocomplete should only return results based on matches inside the post_title.

WooCommerce Custom Attribute being indexed but shows no results

We're running WordPress 4.7, WooCommerce 2.6.9 and the Algolia 1.6.0.
We've got 7 indexes setup:
Searchable posts [searchable_posts]
Posts [posts_post]
Pages [posts_page]
Products [posts_product]
Brands [terms_product_brand]
Product Categories [terms_product_cat]
Full Code [terms_pa_full-code]
The first 6 all return results as expected but Full Code [terms_pa_full-code], although indexed returns no results. However, there should be several 100 if not 1000 as if a product has a Full Code it is set to be 'Visible on the product page'.
Because it's showing as something that can be indexed I'm assuming we don't need to do any custom coding so not sure why it wouldn't display any results?
Has anyone experienced anything similar
The terms_pa_full-code does only contain some metadata, not the values which are them correctly pushed as part of the product data if everything goes well.
You can then use values of that taxonomy as a facet to display a list of available options given a user search query.
You can also register for the Algolia plugin for WooCommerce here: https://community.algolia.com/wordpress/#woocommerce and get this setup for you in a few clicks.

Woocommerce: how do I add metadata to a cart item?

I have a digital product which is described by a quantity and a price, but which also needs 3 more numbers to completely specify it (Unix dates, etc). Problem: how do I get these numbers into the cart?
As far as I can see, there are 2 possible ways to handle this:
A product variation
A product custom field
It looks like variations can only handle discrete values with a limited range (ie. red/yellow/green, S/M/L, etc), and can't handle general integers, like dates. That leaves custom fields. I think I'm right in saying that custom fields are ordinary meta data on the product post page, so I can handle them with get_post_meta and update_post_meta.
So, if I go for custom fields, then I would update the product page field during ordering, and then I would read back the field during checkout, when the WC_Order is created, and add the field to the new order. However, this won't work. I can't change metadata on the product page, because the product is global to all customers, and this operation would interfere with other customers. In other words, you can't store order-specific information in a product, so neither of these options would work.
So, how do I store temporary product metadata and pass it between the ordering and checkout phases (ie. between WC_Cart and WC_Order)?
One option would be to store it as user metadata (or as session data?), but there's got to be a better way - any ideas?
It turns out to be easy to do this with session data. When you're adding an item to the cart (see the source for add_to_cart_action) you create a session variable, containing all your additional meta data:
WC()->session->set(
'my_session_var_name',
array(
'members' => $members,
'start' => $start,
'expiry' => $expiry,
'etc' => $etc));
When the user checks out, the cart data disappears, and a new order is created. You can hook into woocommerce_add_order_item_meta to add the session meta data to the order meta data:
add_action(
'woocommerce_add_order_item_meta', 'hook_new_order_item_meta', 10, 3);
function hook_new_order_item_meta($item_id, $values, $cart_item_key) {
$session_var = 'my_session_var_name';
$session_data = WC()->session->get($session_var);
if(!empty($session_data))
wc_add_order_item_meta($item_id, $session_var, $session_data);
else
error_log("no session data", 0);
}
That's it. You do have to figure out how to get the order metadata out and do something useful with it, though. You may also want to clear the session data, from hooks into woocommerce_before_cart_item_quantity_zero, and woocommerce_cart_emptied. There's gist here which has some example code for this.

How to generate a feed for this category within a Custom Post Type?

How do I generate a feed for the following category? http://digitalxfiles.com/item-cat/wordpress/
The posts in this category comes from a "post-type" so I want to display a category feed from the post type. I tried using ths: http://digitalxfiles.com/category/webhosting/feed/ But it doesn't work.
You can get a feed from a single custom post type by using this link format: http://example.com/feed/?post_type=yourposttype. You can add additional queries onto that if needed to go deeper, like specific categories. So, if you have the item-cat post type and you have the wordpress category, with an id of 42, your link would be: http://example.com/feed/?post_type=item-cat&cat=42.

Resources