Fixes Knowledge base API (#39808)
This commit is contained in:
parent
5f7e20bed7
commit
d77a0dde30
|
@ -136,31 +136,38 @@ class MarketingSpecs {
|
||||||
/**
|
/**
|
||||||
* Load knowledge base posts from WooCommerce.com
|
* Load knowledge base posts from WooCommerce.com
|
||||||
*
|
*
|
||||||
* @param string|null $category Category of posts to retrieve.
|
* @param string|null $term Term of posts to retrieve.
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function get_knowledge_base_posts( ?string $category ): array {
|
public function get_knowledge_base_posts( ?string $term ): array {
|
||||||
$kb_transient = self::KNOWLEDGE_BASE_TRANSIENT;
|
$terms = array(
|
||||||
|
'marketing' => array(
|
||||||
$categories = array(
|
'taxonomy' => 'category',
|
||||||
'marketing' => 1744,
|
'term_id' => 1744,
|
||||||
'coupons' => 25202,
|
'argument' => 'categories',
|
||||||
|
),
|
||||||
|
'coupons' => array(
|
||||||
|
'taxonomy' => 'post_tag',
|
||||||
|
'term_id' => 1377,
|
||||||
|
'argument' => 'tags',
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
// Default to marketing category (if no category set on the kb component).
|
// Default to the marketing category (if no term is set on the kb component).
|
||||||
if ( ! empty( $category ) && array_key_exists( $category, $categories ) ) {
|
if ( empty( $term ) || ! array_key_exists( $term, $terms ) ) {
|
||||||
$category_id = $categories[ $category ];
|
$term = 'marketing';
|
||||||
$kb_transient = $kb_transient . '_' . strtolower( $category );
|
|
||||||
} else {
|
|
||||||
$category_id = $categories['marketing'];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$term_id = $terms[ $term ]['term_id'];
|
||||||
|
$argument = $terms[ $term ]['argument'];
|
||||||
|
$kb_transient = self::KNOWLEDGE_BASE_TRANSIENT . '_' . strtolower( $term );
|
||||||
|
|
||||||
$posts = get_transient( $kb_transient );
|
$posts = get_transient( $kb_transient );
|
||||||
|
|
||||||
if ( false === $posts ) {
|
if ( false === $posts ) {
|
||||||
$request_url = add_query_arg(
|
$request_url = add_query_arg(
|
||||||
array(
|
array(
|
||||||
'categories' => $category_id,
|
$argument => $term_id,
|
||||||
'page' => 1,
|
'page' => 1,
|
||||||
'per_page' => 8,
|
'per_page' => 8,
|
||||||
'_embed' => 1,
|
'_embed' => 1,
|
||||||
|
|
Loading…
Reference in New Issue