display condition based on post term and status

You are populating the $term variable with a multidimensional array, but type-and-value checking it (===) against a string. Second, you say terms are ‘des_1’ and ‘des_1’ (with underscore), but are checking for ‘des-1’ (with dash). wp_get_post_terms will return an array of term objects, so you should might be better of with has_term() for checking if … Read more

Get specific Blocks from Post

PHP-side you can pass the post_content to the parse_blocks() function which will provide you with an array of associative arrays representing each block. Similar functionality is offered JS-side in the form of the wp.blocks.parse() function from the @wordpress/blocks package. For illustrative purposes, here is a var_dump() of that output for the default “Sample Page”: array(9) … Read more

Count products with custom metadata field in an order

{ $userid=””; $integration_status=””; // Get an instance of the WC_Order object $order = wc_get_order( $order_id ); $email = $order->get_billing_email(); $name = $order->get_billing_first_name(); $items = $order->get_items(); $devicecount =0; foreach ( $items as $item ) { $product_name = $item->get_name(); $product_id = $item->get_product_id(); $product_variation_id = $item->get_variation_id(); $productToBeIntegrated=get_post_meta($product_id,’_wootraccar_integration’, true); //$integration_status.=$productToBeIntegrated; if ($productToBeIntegrated==”yes”) { $devicecount = $devicecount + $item->get_quantity(); $integration_status.=$devicecount; … Read more

Get post content intro text on category.php?

You’re using an old version of WordPress. Upgrade to 3.5 and you will no longer see that error. Here’s the function declaration for get_post in WP 3.4: function &get_post(&$post, $output = OBJECT, $filter=”raw”) Notice the ampersand in front of $post? That would mean the value is passed by reference. You can give the function a … Read more

make get_post work in the loop

If you are using setup_postdata( $post ) you need to use the global $post as for some reason it does not work without that specific variable. Once you manually set $post to a new value, you are altering the $post global, so you will need to reset it back to the current post of the … Read more

get posts by tag to showing in a widget

You might want to go through: https://codex.wordpress.org/Class_Reference/WP_Query#Tag_Parameters So using tag parameter in WP_Query, you can get posts tagged to ‘video’ tag. Use orderby and posts_per_page to get last 5 video posts. $query = new WP_Query( array( ‘tag’ => ‘video’, ‘posts_per_page’ => 5 ) ); while ($wp_query->have_posts()) : $wp_query->the_post(); //your code to display posts endwhile; Haven’t … Read more