Is it possible to populate a custom field with content from a page

You can see https://codex.wordpress.org/Plugin_API/Action_Reference/save_post for reference. Here is a quick example of creating/updating meta field when create/updating a page. function save_page( $post_id, $post, $update ) { $post_type = get_post_type( $post_id ); // If this isn’t a ‘page’ post, don’t update it. if ( ‘page’ != $post_type ) return; // Update the post’s metadata. update_post_meta( $post_id, … Read more

Get data from PHP to JavaScript to set position of each post on front page

You could output them as inline CSS custom properties instead of left/top, and then use those to set the position in either CSS or Javascript. PHP: <a class=”project” href=”https://wordpress.stackexchange.com/questions/345335/<?php the_permalink(); ?>” style=”—-x-position: <?php the_field(‘x’); ?>; —-y-position: <?php the_field(‘y’); ?>;'”> <p><?php the_field(“title”); ?></p> </a> CSS: .project { top: var(—-x-position); left: var(—-y-position); /* or CSS grid: */ … Read more

User Meta Value not echoing despite Var_Dump Showing correct string

The $havemeta variable isn’t defined inside your shopping_location_text() function, so it isn’t available for use there. For a quick fix (or for testing/toying) you can move your code inside the function, like this: add_action( ‘woocommerce_before_main_content’, ‘shopping_location_text’, 10 ); function shopping_location_text() { global $current_user; get_currentuserinfo(); // wordpress global variable to fetch logged in user info $userID … Read more

Custom Field Repeating When Using foreach

if you want to use multiple users, if you will add usernames comma separated in custom field. try below code. function user_avatar() { $user = “”; $names = get_post_meta( get_the_ID(), ‘user_name’, true ); $user_names = array_map(‘trim’, explode(‘,’, $names)); if(!empty($user_names)) { foreach ($user_names as $key => $user_name) { $user = get_user_by( ‘login’, $user_name ); if($user) { … Read more