WordPress API functions not working at AJAX functions.php call

Your problem is probably because you do not return a json object but an html (actually mixed text and html), and you set jQuery to validate that the response is json, which it isn’t. your code at the ajax handler should be something like $catshtml = wp_dropdown_categories(…..echo=0); $ret = array(‘data’ => $catshtml); wp_send_json($ret); die(); on … Read more

wp_nav_menu work in functions.php but not in the theme

I had a pre_get_posts. What I missed was this: && $wp_query->is_main_query() This prevents the pre_get_posts to run on the menu query. Full code add_action(“pre_get_posts”, “custom_front_page”); function custom_front_page( $wp_query ){ if( is_admin() ) { return; } if( is_front_page() && $wp_query->is_main_query() ) { $wp_query->set(‘post_type’, ‘produkt’); $wp_query->set(‘page_id’, ”); $wp_query->is_page = 0; $wp_query->is_singular = 0; $wp_query->is_post_type_archive = 1; $wp_query->is_archive … Read more

Sort and paginate custom post taxonomies alphabetically

As I stated in comments, you can either use usort() to sort the returned array of terms, or you can just use wp_get_post_terms() which is already sorted by default by name in ascending order $terms = wp_get_post_terms( get_the_ID(), ‘brand’ ); var_dump( $terms ); EDIT Here is an example with usort() and get_the_terms() $terms = get_the_terms( … Read more

How to organize functions.php content

As @Tom J Nowell says, don’t nest functions. Just write them normally: function my_theme_prefix_setup() { // Add theme support etc. } add_action( ‘after_setup_theme’, ‘my_theme_prefix_setup’ ); function my_theme_prefix_init() { // Register a post type } add_action( ‘init’, ‘my_theme_prefix_init’ ); Or using a class: class my_theme { function __construct() { add_action( ‘after_setup_theme’, array( $this, ‘setup’ ) ); … Read more