Push metadata in array

You need to loop through your posts, and retrieve the metadata for each post. Add them to your array, and encode them to JSON. $posts = $query->get_posts(); foreach( $posts as &$thispost ) { // reference the current item $thispost->meta = get_post_meta( $thispost->ID ); } Now you got a WP_Post-Object, with all the post meta available … Read more

add_action shortcut?

From the WordPress development reference, the add_action function requires two parameters with an optional two. The first parameter, $tag is a string that is the name of the action to which the $function_to_add is hooked. The second parameter, $function_to_add is a callable that the WordPress developer reference states is “the name of the function you … Read more

WP Query with custom Shortcode

There are few issue with your code When using WP_Query in conjuction with the_post() or using get_posts() in conjuction with setup_postdata( $post ), you need to reset the $post global with wp_reset_postdata(), not wp_reset_query(). wp_reset_query() is used in conjuction with query_posts() which you should never ever use You would want to reset posdata between your … Read more

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