WordPress: How to use post_class() in an echo

The post_class() function just is a wrapper for get_post_class(). Keep in mind that the latter does not echo, but returns an Array so you have to do something like what post_class() does: $classes = join( ‘ ‘, get_post_class() ); Your code (could) would look like the following. I changed the if check as well to … Read more

Getting an array out of WPQuery

Your function returns $product->get_id();, instead of that, you should save those values into an array and at the end return that array. function ids(){ $args = array( ‘numberposts’ => -1, ‘post_type’ => ‘product’, ‘meta_key’ => ‘wppl_is_dax’, ‘meta_value’ => ‘1’ ); // query $the_query = new WP_Query( $args ); $allIds = array(); if( $the_query->have_posts() ): while( … Read more

Autogenerate wordpress shortcodes using array?

Auto-generate shortcodes from an array: You can try the following Shortcode Automat: /** * Setup the Shortcode Automat * */ function shortcode_automat_setup() { $settings = array( “get_address” => “mg_admin_address”, “get_phone” => “mg_admin_phone”, “get_fax” => “mg_admin_fax”, “get_email” => “mg_admin_email”, “get_hrs_mon” => “mg_work_hrs_mon_frd”, “get_hrs_sat” => “mg_work_hrs_sat” ); $sc = new ShortCodeAutomat( $settings ); $sc->generate(); } add_action( ‘wp_loaded’, … Read more

How to build widget with arrays inside arrays?

get_field_id prepare prefix for field id, within one widget instance it’s always the same. Your form fields probably look similar to these: // — $element[0] — // $field[icontxt] <input class=”widefat” id=”widget-baseid-instance-inner_elements” name=”widget-baseid[instance][inner_elements][0]” value=”%4$s”> // $field[iconlnk] <input class=”widefat” id=”widget-baseid-instance-inner_elements” name=”widget-baseid[instance][inner_elements][0]” value=”%4$s”> //$field[iconlnktrgt] <input class=”widefat” id=”widget-baseid-instance-inner_elements” name=”widget-baseid[instance][inner_elements][0]” value=”%4$s”> // — $element[1] — <input class=”widefat” id=”widget-baseid-instance-inner_elements” name=”widget-baseid[instance][inner_elements][1]” value=”%4$s”> … Read more