Setting All Drafts to ‘exclude-from-catalog’ in WooCommerce

Look into wp_set_object_terms() You could do something along the lines of: wp_set_object_terms( $post_id, ‘exclude-from-catalog’, ‘product_visibility’ ); Getting all posts by status, use Wp_Query. I added the ‘fields’ => ‘ids’ param to limit the query to only ids, rather than gathering whole post objects. On an array of posts that have Draft or Pending as a … Read more

Parsing php string in jquery [closed]

Well it seems @JacobPeattie mentioned to use json, I just echoing that. First json encode the variable $array = json_encode($out); Then send this value echo ‘<div data-ad = ‘.$array.’ class=”ash_loadmore”><span>LOAD MORE</span></div>’; To get that echo json_encode($_POST[‘ad’]) I think that’s it.BTW you don’t have now that string problem as the output will be like this {“footer-insta”:2,”sidebar-1″:3} … Read more

Shortcode return function with link href inside PHP

You can use ob_start and ob_get_clean to print out your shortcode. function shortcode_html() ob_start(); ?> <div class=”boxed max-width”> <div class=”indice-title”> <span><?php echo $content; ?></span> <i class=”fa fa-twitter” aria-hidden=”true”></i> </div> </div> <?php return ob_get_clean(); } add_shortcode( ‘print_shortcode’, ‘shortcode_html’ );

How can I generate random numbers inside my shortcodes on each implementation?

According to @Mark Kaplun comment: Make your getRandomCode() return value instead of echo like this function getRandomCode(){ $alphanumeric = “0123456789abcdefghijklmnopqrstuvwxyz”; $su = strlen($alphanumeric) – 1; // echo ‘<br/>’; // // echo rand(0, $su); // // echo ‘<br/>’; // // echo substr($alphanumeric, rand(0, $su), 3); // // echo ‘<br/>’; return substr($alphanumeric, rand(0, $su), 3) . substr($alphanumeric, … Read more

An unwanted inline style is added to my body tag

After searching a lot, I realized that elements inside my head tag are shown inside body tag and head tag contains nothing in my generated HTML code. This happened because I had used UTF-8-BOM encoding and by changing it to simple UTF-8 everything was fixed.

wp_insert_post() is returning the correct post ID, no failure, but the post content does not get updated

Don’t bother fixing your AJAX callback, there’s already a REST API endpoint that’s well tested and does all of this out of the box: example.com/wp-json/wp/v2/zen_page So lets enqueue a helper script to give us the URL and a security token/nonce: wp_enqueue_script( ‘wp-api’ ); You will must enable the REST API for your custom post type … Read more

wp-load Without Loading the plugins

You would need to put something like this in a .php file of any name in your must-use plugins folder (/wp-content/mu-plugins/) so that it loads before all plugins so you can use it to filter the plugin loading… <?php if (defined(‘SHORTINIT’) && SHORTINIT) { add_filter(‘option_active_plugins’, ‘shortinit_plugins_filter’); function shortinit_plugins_filter($plugins) { $noloadplugins = array(‘w3-total-cache’); foreach ($plugins as … Read more