Create Shortcode for php code in functions.php

I have this PHP code that shows a related posts element created using advanced custom fields plugin. I want to create a shortcode inside functions.php with the code and then use the shortcode in a text element of a page builder. Would someone kindly assist me with the modified code to put inside functions.php? Thanks <?php $posts = get_field(‘related_posts’, false, false); $loop = new WP_Query(array(‘post_type’ => ‘post’, ‘posts_per_page’ => 3, ‘post__in’ => $posts, ‘post_status’ => ‘publish’, ‘orderby’ => ‘post__in’, ‘order’ => ‘ASC’ )); if($loop->have_posts()) { ?> <div class= »rel-posts »> <?php while…

How to fix “Supplied nav_menu_item value missing property” after update to WordPress 5.0

Please help. We have page on WordPress with our custom theme and minimum plugins. After update WordPress from 4.9 to 5.0.2 we have error in the admin page on Themes => Customize. Everything else is working. I try turn off and on foreign plugins (except WP bakery). Thanks. Fatal error: Uncaught Exception: Supplied nav_menu_item value missing property: description in /wp-includes/customize/class-wp-customize-nav-menu-item-setting.php:183 Stack trace: #0 /wp-includes/class-wp-customize-nav-menus.php(692): WP_Customize_Nav_Menu_Item_Setting->__construct(Object(WP_Customize_Manager), ‘nav_menu_item[7…’, Array) #1 /wp-includes/class-wp-hook.php(286): WP_Customize_Nav_Menus->customize_register(Object(WP_Customize_Manager)) #2 /wp-includes/class-wp-hook.php(310): WP_Hook->apply_filters(NULL, Array) #3 /wp-includes/plugin.php(453): WP_Hook->do_action(Array) #4 /wp-includes/customize/class-wp-customize-nav-menu-item-setting.php on line 183 Source: https://wordpress.stackexchange.com/feeds

Displaying Custom Input Value to Customer Order Details (My Account) page in Woocommerce

I have been looking for a solution to display a custom input field on Checkout page in Payment option area when Cash ON Delivery option is selected. Upon selection it displays a field in which customer inputs a value and the data is sent to the admin order details page. This is what I came up with. I inserted this code in checkout/payment-method.php <?php if ( $gateway->has_fields() || /* $gateway->get_description() && */ $gateway->id != « cod » ) : ?> <?php endif; ?> <?php if ( $gateway->id == « cod » ) : ?>…

WooCommerce ‘all’ orders no longer being displayed – how may I debug/fix

I’ve just noticed that we seem to have a bug with our store. The ‘all’ orders selection is showing as empty but the other sub catergories such as completed, on hold and pending etc are there. I’m not sure what could’ve caused this, I presume a plugin or an update but I’m also not sure how to debug or get into the logs to check. Any advice would be brilliant, thank you. Source: https://wordpress.stackexchange.com/feeds

Add custom attribute to product’s HTML to woocommerce cart page

I’m trying to add a data-attribute to WooCommerce’s cart page. The cart page populates a table with each row being a product that has been added to the cart. I’m able to add a data attribute into the HTML for this row like so: /wp-content/plugins/woocommerce/templates/cart/cart.php <?php // For each item in cart foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { // Get product $_product = apply_filters( ‘woocommerce_cart_item_product’, $cart_item[‘data’], $cart_item, $cart_item_key ); // Get custom attribute $foobar = $_product->get_attribute( ‘myCustomAttribute’ ); $foobar == true ? $foo = « true » : $foo…

wp_query get data from advanced custom field in wordpress

I want to get the data from advanced custom field using wp_query from another custom post type: $title = get_the_title(); $the_query = new WP_Query( array( ‘posts_per_page’=>9, ‘post_type’=>’product_name’, ‘order’ => ‘ASC’, ‘brand_name’ => $title, /*brand_name is my custom field name*/ ‘paged’ => get_query_var(‘paged’) ? get_query_var(‘paged’) : 1) ); Source: https://wordpress.stackexchange.com/feeds

Show all posts in sidebar in single.php

WordPress 4.x Why does the loop.php only show the current post in the sidebar when I view a post in single.php? I have: Post One Post Two Post Three If I view « Post One » (single.php), the sidebar only shows « Post One », if I view the page I have set as the « Blog » page (index.php) in WordPress admin, I see all the posts in the sidebar. My goal is to have all posts show in the single.php sidebar. Would be nice to remove the current posts as well! But mostly want…

In a multisite, how can I get posts from one site and display their permalinks in another site?

I have a WordPress multisite with one main site and four sub-sites. In a PHP template on my main site, I would like to get the posts from one of the sub-sites and print the permalinks to the page. How is this done? My code is below–when this code is executed, permalinks are indeed printed to the screen, but they are incorrect–the post name is correct, but the path is incorrect. $tp_blog_id = 4; switch_to_blog( $tp_blog_id ); $posts = get_posts( array( ‘post_type’ => ‘property’, ‘posts_per_page’ => 100, ‘numberposts’ => -1…

Integrating PHP into Javascript to display map markers with Google API – problem with wp_localize

I would display Google maps markers on custom site temple with Google API maps. I do everything like this post: Integrating PHP into Javascript to display map markers with Google API But a console gives me an error, I don’t know where I can look for the error. (index):774 Uncaught (in promise) ReferenceError: storeData is not defined at initMap ((index):774) at js?key=AIzaSyAg-GBNbwLWCxiN-UI-0COkr1bgAKpXjQU&callback=initMap:123 at js?key=AIzaSyAg-GBNbwLWCxiN-UI-0COkr1bgAKpXjQU&callback=initMap:123 I think the WordPress first try to use wp_localize, then load jquery. Or WordPress don’t know how to connect jquery-core with jquery CDN. Code of my…