How can I alter this code to accept a slug as well as an ID?

The Codex essentially explains how to do this: if ( $category_to_check = get_term_by( ‘name’, ‘fruit’, ‘category’ )) post_is_in_descendant_category($category_to_check->term_id); https://codex.wordpress.org/Function_Reference/in_category#Testing_if_a_post_is_in_a_descendant_category Putting it all together in your function you would have: if ( ! function_exists( ‘post_is_in_descendant_category’ ) ) { function post_is_in_descendant_category( $cats, $_post = null ) { foreach ( (array) $cats as $cat ) { if (!absint($cat)) … Read more

WordPress plugin won’t create custom tables

dbDelta() is picky– maddeningly picky. You must put each field on its own line in your SQL statement. You must have two spaces between the words PRIMARY KEY and the definition of your primary key. You must use the key word KEY rather than its synonym INDEX and you must include at least one KEY. … Read more

Echo array value

If you just need to have the print_array($var) provide an array of values, then you need to change the database function from $wpdb->get_results to $wpdb->get_var. You are retrieving just one value from the database, so get_var is the function which will return that specific value directly. Edit: You can create a comma separated list from … Read more

How to debug failed changes to posts?

I was finally able to get this to work by using php5-fpm instead of php5-cgi. First I removed the php5-cgi package via sudo apt-get autoremove –purge php5-cgi Then I installed php5-fpm via: sudo apt-get install php5-fpm After tweaking my server definition in Nginx a bit, the problem went away. Update I suspect this had more … Read more

Unexpected token ILLEGAL, even on clean install – jquery-issue?

It looks to me like you’re trying to utilize jQuery in custom code, but haven’t actually enqueue’d the jQuery script – This line gives it away (I think?): ReferenceError: jQuery is not defined if you are using wp_enqueue_script to bring in a custom .js file, make sure you set jquery as a dependancy wp_enqueue_script( ‘my-script’, … Read more

ACF checkbox array is returning numbers, not labels [closed]

ACF is actually doing what it should – storing a numerical array of selected values. If you want the label you can levy get_field_object, which returns information about the custom field (rather than the value of it for the given post). $field_obj = get_field_object( ‘nav_widget_platforms’ ); $platforms = get_field( ‘nav_widget_platforms’ ); foreach ( $platforms as … Read more