calling a custom field value inside functions.php

if you’re not planning on adding much html there is no need to use ob_start just return the php: function wpb_description_shortcode( ){ if (get_post_meta(get_the_ID(), ‘song_number’, true)) { return get_post_meta(get_the_ID(), ‘song_number’, true).'<br/>’; } else { return; } } // Register shortcode add_shortcode(‘my_description_number’, ‘wpb_description_shortcode’); I’m not sure what this data is, but it would be a good … Read more

How to catch wordpress post ID when it’s published

To put it briefly, WordPress hooks let you modify parameters or output of functions (filters) or execute custom code when something happens (actions). Both types of hooks usually pass one or more arguments to the callback functions that are attached to them. During a page request WordPress goes through series of steps to get the … Read more

Load Posts on Click via Ajax into a DIV

The short answer to your question is simply, yes it is possible. It involves code across JS and PHP and is beyond what I would be able to show in an answer here. However I did a simple Google search for “wordpress load posts with ajax” and this link is the first result. https://wpmudev.com/blog/load-posts-ajax/ I … Read more

Permission callback to check if user has application password

You’re conflating roles/capabilities and application passwords. This problem has nothing to do with application passwords. Application passwords are a way of authenticating who, that you are who you say you are. permission_callback isn’t interested in that though, just because you are indeed verified as you, does not mean you have permission to do what you’re … Read more

Why is a wp function used in current PHP namespace’s callback not resolved to global scope?

From your comment: Apparently the function can indeed not be used on the frontend in wp (see here), can anyone confirm this? I can confirm that the post_exists() function can be used on the front-end, but you need to manually load the file that defines the function, which is wp-admin/includes/post.php — see the “File: <path>” … Read more

Get access to variable from previous pageview, excluding ajax-calls

I found out you could identify ajax requests by the following if-statement if (defined(‘DOING_AJAX’) && DOING_AJAX) So problem solved using add_action(‘init’, ‘set_global_pixelcapival’); function set_global_pixelcapival() { if (defined(‘DOING_AJAX’) && DOING_AJAX) { } else { global $pixelcapival; $pixelcapival = pixelcapival(); global $prev_pixelcapival; $prev_pixelcapival=””; if(isset($_COOKIE[‘pixelcapival’])) { $prev_pixelcapival = $_COOKIE[‘pixelcapival’]; } setcookie(‘pixelcapival’, $pixelcapival, time() + 1200, “https://wordpress.stackexchange.com/”); } }

Display Yoast meta-description `wpseo_desc` within loop of categories and fail silently if no data is set [closed]

You can just check if $meta and $meta_desc exist. If not, don’t echo anything. $popular_topics = get_field(‘popular_topics’); if ( $popular_topics ) : foreach ( $popular_topics as $topic ) : $id = $topic->term_id; $meta = get_option(‘wpseo_taxonomy_meta’); if ( $id && ( $meta && !empty($meta) ) ) : $meta_desc = $meta[‘category’][$id][‘wpseo_desc’]; if ( $meta_desc ) : ?> … Read more

Automatically add images to a menu

I guess you need this function get_the_post_thumbnail_url($menu->object_id); (provided menu item is not a custom link) $menu->ID is not the id of the post/page it is linking to. About calling meta yes it is also possible $image_url = get_post_meta( $menu->object_id, ‘meta_key’, true );

WordPress Custom SQL Table with UserID Filter for results

The evolution of this question makes it difficult to succinctly answer, but in brief summary: Using $wpdb->prepare() to construct arbitrary SQL queries to execute against the database helps to mitigate injection vulnerabilities by escaping inserted variables. To use it, instead of concatenating or directly inserting variables into the query, use a placeholder for the appropriate … Read more