Call global variable array() in woocommerce child/template

It is all fine. You just need to declare variable global first then you can set the value of this and access globally. function my_free_shipping( $is_available ) { global $woocommerce, $product_notfree_ship; // set the product ids that are $product_notfree_ship $product_notfree_ship = array( ‘1’, ‘2’, ‘3’, ‘4’, ‘5’ ); Then again declare it globally when using … Read more

Different loop output every x posts in custom post type

After quite a bit of trial and error, I got the code set up correctly for the WordPress loop. I put it into a shortcode. Here it is: add_shortcode( ‘partnerlogos’, ‘display_partner_logos’ ); function display_partner_logos(){ // Define the query $args = array( ‘post_type’ => ‘dnf_partner_logos’, ‘post_status’ => ‘publish’ ); $query = new WP_Query( $args ); ?> … Read more

Create WP_Query to search for posts by their categories or their parent/child categories

Use get_categories first to get all the post categories to use in the form, then loop through them to display a multicheck input… function hierarchical_category_inputs ($cat, $indent) { $cats = get_categories(‘hide_empty=false&orderby=name&order=ASC&parent=”.$cat); $indent++; if ($cats) { foreach ($cats as $cat) { echo “<input type=”checkbox’ name=”cat-“.$cat->term_id.”””; echo ” style=”margin-left: “.($indent*10).”px;”> “.$cat->name.”<br>”; hierarchical_category_inputs($cat->term_id, $indent); } } } echo … Read more

Custom Form Processing Issue

Instead of sending the form to a custom PHP script where you must load WordPress manually, you should send the from directly to a WordPress page. You could use admin_post_{action} hook, it is similar to how admin-ajax.php works, but used to handle GET and POST requests. The form: <form action=”<?php echo admin_url( ‘admin-post.php’ ); ?>” … Read more

Accessing data from a non-WP database/table within a page content

<?php $mydb = new wpdb(‘uid’,’passwd’,’database’,’localhost’); $mydb->show_errors(); $query = “SELECT DATE_FORMAT(col1, ‘%d-%b’) AS Pdate, DATE_FORMAT(col1, ‘%Y’) AS Pyear, col2, col3, col4, col5 AS fname FROM table ORDER BY col1 DESC LIMIT 50”; $result = $mydb->get_results($query); echo $mydb->num_rows . ‘ in table ‘; ?>

Creating a Multi-Level Associative Object Using AJAX

If you want to pass a complex value, your best path is probably to jsonify it. Something like $.post( MyAjax.ajaxurl, { action: ‘my_action’, someValue: JSON.stringify({ one: ‘Some Value One’, two: ‘Some Value Two’, three: ‘Some Value Three’, four: ‘Some Value Four’, }) } ); and then on the server side you decode the value with … Read more

RecursiveDirectoryIterator not working in admin

I think the problem is with your relative path. When you visit the /wp-admin/, it will try to locate the wp-content/themes/vac3/acf within and it doesn’t find it there. Try instead the full path with help of __DIR__ or get_template_directory() – more details in this blog post. What if you later remove the acf/ subdirectory? You might … Read more