ACF: post query, hide duplicate values [closed]

You could pass all the fields into an array during your while loop, strip the array of duplicates, and then run a foreach loop on that array. It would look something like this: <?php $designers = array(); while ( $the_query->have_posts() ) : $the_query->the_post(); $designers[] = get_field(‘products_page_designer_name’); endwhile; // This will strip out any values that … Read more

Add custom text color WordPress 3.9 TinyMCE 4 Visual editor

Aleksandar Urošević addressed this specific scenario (which is different than adding a button, as you’ve noted). This is the WP 3.9 approach: function mytheme_change_tinymce_colors( $init ) { $default_colours=” “000000”, “Black”, “993300”, “Burnt orange”, “333300”, “Dark olive”, “003300”, “Dark green”, “003366”, “Dark azure”, “000080”, “Navy Blue”, “333399”, “Indigo”, “333333”, “Very dark gray”, “800000”, “Maroon”, “FF6600”, “Orange”, … Read more

Stop WordPress processing Javascript as text

The post editor is really not meant for inserting functional code like JavaScript into the page. Anything you put through the post editor will get run through wpautop() before output, which is what adds the paragraph tags — even if you enter it via the Text mode. I’d suggest outputting your JavaScript via a hook … Read more

Hack-Proof OR Security in WordPress — is it real?

But recent months, several sites of my clients were hacked and I’m concerned about this problem. In my experience pattern of hacks in quick succession indicates a common link. Typically it is vulnerable plugin/theme or incompetent hosting. If you do not consider the option of password brootforcing, how hackers can get access to the file … Read more

WooCommerce search products between price range using WP_Query

The solution: $query = array( ‘post_status’ => ‘publish’, ‘post_type’ => ‘product’, ‘posts_per_page’ => 10, ‘meta_query’ => array( array( ‘key’ => ‘_price’, ‘value’ => array(50, 100), ‘compare’ => ‘BETWEEN’, ‘type’ => ‘NUMERIC’ ), ), ); $wpquery = WP_Query($query); // return 10 products within the price range 50 – 100

Plugin init hook fires repeatedly

This happens because you are not excluding ajax requests. Check this example from the WordPress Codex for the admin_init hook which is also valid for the init hook and see how AJAX requests are exluded in the if using the DOING_AJAX constant: /** * Restrict access to the administration screens. * * Only administrators will … Read more

How to add single function for all WordPress hooks

There is a special action all that you can use. Be aware, this will be very slow, don’t do that in production. Here is an example: add_action( ‘all’, function() { static $hooks = []; $filter = current_filter(); if ( isset ( $hooks[ $filter ] ) ) return; $types = array_map( function ( $arg ) { … Read more

add_action in a custom plugin

It errors because class method is not a function. It’s not uniquely identified by its name alone. You need to provide instance of the object (or name of the class for static methods). In your context it would be: add_action( ‘init’, [ $this, ‘newsletterSuscriber’ ] );