Created
November 5, 2023 02:29
-
-
Save hssktm/be0dfa1378974f82b8b3efa637acb670 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function repeater_tax_results($categories, $query) { | |
if ('kiujhhjkhjku' == $query->get('post_type')) { | |
$categories = array(); | |
$category_query = new WP_Term_Query(array( | |
'taxonomy' => 'category', // Change 'category' to the taxonomy you want to query. | |
'hide_empty' => false, | |
'exclude' => get_cat_ID('Uncategorized'), // Exclude the 'Uncategorized' category | |
)); | |
$category_results = $category_query->get_terms(); | |
// Category term fields | |
foreach ($category_results as $category) { | |
$category_data = (object)array( | |
'category_name' => $category->name, // The category name. | |
'category_description' => $category->description, // The category description. | |
'category_id' => $category->term_id, // The unique ID of the category in the WordPress database. | |
'category_slug' => $category->slug, // The category slug. | |
'category_parent' => $category->parent, // The ID of the parent category (if it has one). | |
'category_url' => get_term_link($category), // Get the category link. | |
// This is a placeholder for post content. Do not remove it, as WordPress uses it for searches and other functions. | |
'post_content' => '', | |
); | |
// Check if ACF (Advanced Custom Fields) is installed | |
if (function_exists('get_fields')) { | |
// ACF fields for categories | |
$fields_acf = get_fields('category_' . $category->term_id); | |
if ($fields_acf) { | |
foreach ($fields_acf as $field_name_acf => $field_value_acf) { | |
$category_data->$field_name_acf = $field_value_acf; | |
} | |
} | |
} | |
$categories[] = $category_data; | |
} | |
} | |
return $categories; | |
} | |
add_filter('posts_results', 'repeater_tax_results', 10, 2); | |
function custom_field($value) { | |
global $post; | |
return $post->$value; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment