In 2016 theme, how can I force all single attachment posts to use content-attachment.php rather than image.php?

There’s a couple things you could do. If we follow the Template Hierarchy you could rename your content-attachment.php file to attachment.php and remove image.php. This will ensure that the image view will fallback to attachment.php. If you want to use content-attachment.php then you could use the template_include hook to tell WordPress to load in which … Read more

How to hook into debug.log?

WordPress tells PHP, using ini_set(), in wp_debug_mode() which errors should be handled and which file they should be written to. The function is called in wp-settings.php when WP is starting up. As suggested by David in How to catch all PHP errors with custom error handler? answers you could use PHP’s set_error_handler() to define a … Read more

Is it possible to tokenize theme options to make them available to the basic site editor

Ok through much research, I came up with a way to do this through my theme without having to create a separated plugin. First I set the options in the back end (I am using Redux Framework WP Plugin): <?php Redux::setSection(‘z_theme_opt’, array( ‘title’ => esc_html__(‘Page Tokens’, ‘z_theme’), ‘id’ => ‘opt_page_tokens’, ‘icon’ => ‘dashicons dashicons-html’, ‘fields’ … Read more

wp db request without refreshing the page

Instead of querying the database directly, you could use WP_User_Query, but you’ll get the best results by querying the REST API endpoint with a GET request at /wp-json/wp/v2/users which already lists out the users in a WordPress install. Just remember to account for pagination.

Including Google Map within a wordpress plugin

Problem 1 neither I see the function initMap in the footer. This is because of the action here: add_action(‘wp-footer’, [$this, ‘init_google_map’]); There is no wp-footer hook. You probably intended to use wp_footer: https://developer.wordpress.org/reference/hooks/wp_footer/ Though keep in mind this isn’t guaranteed to be in a footer, just at the end of the HTML document before the … Read more

Issue with dynamically populating address fields with Gravity Forms

The following code fixed my issue: if ( $field->type == ‘address’ && is_array( $field->inputs ) ) { foreach ( $field->inputs as &$input ) { $input_name = rgar( $input, ‘name’ ); if ( $input_name && in_array( $input_name, $address_fields ) ) { $current_value = get_post_meta( $post_id_cid, $input_name, true ); if ( $current_value ) { $input[‘defaultValue’] = $current_value; … Read more

Passing a variable containing a comma separated list of values in a meta-query

In WordPress meta queries, when using the ‘compare’ => ‘IN’ comparison, the value should be an array, not a string. When you manually input array( ‘1302’, ‘1329’ ), it works because it’s correctly formatted as an array. However, when using $artists_string_value, it’s treated as a single string, not an array of values. You should modify … Read more

Where can I store data in WordPress?

In my experience, update_option() and update_post_meta() are what I need over 90% of the time. Use update_option() if you want to save data related to the site overall, and use update_post_meta() if you want to save data related to a specific post. The other ~10% of the time I might need something more esoteric, like … Read more

How to get a list of all posts and their categories?

If you want to export the data to a CSV or JSON file directly from the SQL query, you can use the MySQL INTO OUTFILE clause. SELECT wpd9_posts.post_title, GROUP_CONCAT(wpd9_terms.name) AS categories FROM wpd9_posts LEFT JOIN wpd9_term_relationships ON (wpd9_posts.ID = wpd9_term_relationships.object_id) LEFT JOIN wpd9_term_taxonomy ON (wpd9_term_relationships.term_taxonomy_id = wpd9_term_taxonomy.term_taxonomy_id) LEFT JOIN wpd9_terms ON (wpd9_term_taxonomy.term_id = wpd9_terms.term_id) WHERE … Read more