Getting value from Advanced Custom Fields [closed]

You are trying to use get_field_object, which isn’t correct. What you should be using is get_field() or the_field(). Example get_field(): $value = get_field( “locations” ); if( $value ) { echo $value; } else { echo ’empty’; } Example the_field(): <p><?php the_field(‘locations’); ?></p> Note: ACF has great documentation, you should look it over.

Plugin echos text from shortcode function in gutenberg page editor

As Milo noticed, shortcodes should return content instead of echoing it. So change while($query1->have_posts()) : $query1->the_post(); echo ‘<div class=”menu-thumb”>’; the_post_thumbnail( ); echo ‘</div>’; echo ‘<div class=”menu-title”>’; the_title( ); echo ‘</div>’; echo ‘<div class=”menu-content”>’; the_content( ); echo ‘</div>’; endwhile; to while($query1->have_posts()) : $query1->the_post(); $div = ‘<div class=”menu-thumb”>’; $div .= get_the_post_thumbnail( ); $div .= ‘</div>’; $div .= … Read more

Detect permalinks when passing querystring in REST API requests

In more recent browsers (everything but IE, essentially), there are some useful APIs for working with URLs that will make this easier: let url = new URL( MY_PLUGIN_WP_REST_API_CONFIG.baseUrl ); url.searchParams.append( ‘per_page’, 100 ); url.searchParams.append( ‘order’, ‘asc’ ); fetch( url.toString() ).then(); With those methods the per_page and order parameters will be added correctly regardless of whether … Read more

Custom form action to handle data inside a plugin

admin-post.php is perfect for that. You have to do three things: 1. Set action for your form to admin-post.php <form method=”post” action=”<?php echo admin_url(‘admin-post.php’); ?>”> 2. Add hidden input with name=action <input type=”hidden” name=”action” value=”my_plugin_action” /> 3. Register your callbacks for admin_post_{$action} and admin_post_nopriv_{$action}: add_action( ‘admin_post_my_plugin_action’, ‘my_form_processor’ ); add_action( ‘admin_post_nopriv_my_plugin_action’, ‘my_form_processor’ ); function my_form_processor() { … Read more

Dropdown menu on custom page with product to choose number of products per page

Maybe this would work? function ps_pre_get_products_query( $query ) { $per_page = filter_input(INPUT_GET, ‘perpage’, FILTER_SANITIZE_NUMBER_INT); if ( ! is_admin() && is_woocommerce() && is_page() ) { $query->set( ‘posts_per_page’, $per_page ); } } I tested your code and the if statement didn’t seem to work with is_page() (but that could also be because my local WP sandbox is … Read more