Make custom field meta not display if there is not data in it

It could be that there are rows being returned for: have_rows(‘google_drive_links’) but then, nothing returned for the sub fields? $content = get_sub_field(‘google_link_name’); $link = get_sub_field(‘google_link’); Perhaps you could put in an extra check for those two before creating the hr and ul? if (get_sub_field(‘google_link_name’) && get_sub_field(‘google_link’)){ // Create the hr and ul } Depending on … Read more

Problems with function on function.php

Did you try to use add_action without priority? On the last line, you specify the priority. Lower numbers correspond with earlier execution, and functions with the same priority are executed in the order in which they were added to the action. function test_1234567() { // Get term by name ”news” in Categories taxonomy. $category = … Read more

Generate an array of parent/child page IDs, based on parent page name

OK, so what we want to achieve is to write a function that will take a title of a page and return the array containing its ID and IDs of its children. So here’s the code: function get_page_and_its_children_ids_by_title( $page_title ) { $result = array(); $page = get_page_by_title( $page_title ); // find page with given title … Read more

Woocommerce: Is it possible to overide the settings for allowing to purchase out of stock products [closed]

The following hooked functions will allow you to make everything purchasable: // Change all products stock statuses to ‘instock’ add_filter( ‘woocommerce_product_get_stock_status’, ‘filter_get_stock_status_callback’, 10, 2 ); add_filter( ‘woocommerce_product_variation_get_stock_status’, ‘filter_get_stock_status_callback’, 10, 2 ); function filter_get_stock_status_callback( $stock_status, $product ){ return is_admin() ? $stock_status : ‘instock’; } // Enable backorders on all products add_filter( ‘woocommerce_product_get_backorders’, ‘filter_get_backorders_callback’, 10, 2 ); … Read more

Append a term to WooCommerce product existing product category terms

You just need to add a missing boolean argument in wp_set_object_terms() function like: wp_set_object_terms($post->ID, $term->term_id, ‘product_cat’, true); This time the term will be appended and not replaced. You should check that the term doesn’t exist yet on the product, before appending it like: add_action( ‘transition_post_status’, ‘new_product_add’, 10, 3 ); function new_product_add( $new_status, $old_status, $post ) … Read more

Output a WooCommerce product custom field in WooCommerce using get_post_meta()

There are some errors as get_post_meta() first argument need to be a defined product ID here (and in your code post_ID is not even dynamic variable and will not give anything)… Try the following: <?php function check_gtin(){ if ( $gtin = get_post_meta(get_the_id(), ‘gtin’, true) ){ echo “gtin13:”. $gtin; } else { echo ‘identifier_exits:false’; } } … Read more

Error: array_map(): Argument #2

(Revised answer, based on the code in question and this) After the discussion, I realized that: You should replace the post__not_in with tag; i.e. use ‘tag’ => $tag. You should also understand that post__not_in should be an array of post IDs and not tag/category slugs, names, etc. And if you don’t pass an array, then … Read more

How to get the post_id from postmeta

There’s the WordPress meta API for retrieving meta values from the wp_postmeta table, but the API doesn’t provide a function for retrieving the post ID (post_id value), but you can use custom SQL as in your code. However, $wpdb->get_col() returns an array of values (upon success), so that’s why you get the “Array” when you … Read more

Create custom blocks for bootstrap

Rather than create new blocks to represent the Bootstrap classes. You should enqueue the bootstrap js and css files in your theme as you say you normally do. Once bootstrap has been added to the theme, you can simply assign the bootstrap css classes to the already existing Gutenberg blocks. As demonstrated in the following … Read more