How to get the post_id from postmeta

There’s the WordPress meta API for retrieving meta values from the wp_postmeta table, but the API doesn’t provide a function for retrieving the post ID (post_id value), but you can use custom SQL as in your code. However, $wpdb->get_col() returns an array of values (upon success), so that’s why you get the “Array” when you … Read more

Create custom blocks for bootstrap

Rather than create new blocks to represent the Bootstrap classes. You should enqueue the bootstrap js and css files in your theme as you say you normally do. Once bootstrap has been added to the theme, you can simply assign the bootstrap css classes to the already existing Gutenberg blocks. As demonstrated in the following … Read more

Displaying Logged-In User Name and avatar in WordPress Menu

You can use “get_avatar” function to display avatar in menu with user name. Please try code given below: add_filter( ‘wp_nav_menu_objects’, ‘my_dynamic_menu_items’, 10 ); function my_dynamic_menu_items( $menu_items ) { foreach ( $menu_items as $menu_item ) { if ( strpos($menu_item->title, ‘#profile_name#’) !== false) { $menu_item->title = str_replace(“#profile_name#”, wp_get_current_user()->user_login .’ ‘. get_avatar( wp_get_current_user()->user_email, 50), $menu_item->title); } } return … Read more

Problem with WordPress Ajax form

Ok, after a lengthy discussion Edegist and I actually sorted this all out. Here’s a couple of the key factors that comprise the solution. One, we had to loop through all of the selected checkboxes to pass via AJAX. jQuery( document ).ready( function( $ ) { $( ‘.kvo_ajax_submit_button’ ).click( function( e ) { e.preventDefault(); var … Read more

New Plugin Review

Now I’ve seen your code, I think the reviewer is wrong: they’re talking about the form in agg-as-options.php, which is handled the way I describe below except they’re wrong: the form is processed in the agg_options function, not outside of a function as they say this is only shown and processed on the admin aggregate-options … Read more

Creating an Exit Confirmation Popup

First things first, change the name of the functions – you have them the same as the tutorial – as a rule, always make them something unique just to reduce the possibility of conflicts. So instead of wpb_confirm_leaving() you should maybe change it to something like jkkr_confirm_leaving. Just make sure you change it everywhere. But … Read more

How to do conditional publishing?

That’s because the hook “transition_post_status” is called: After the post has been published or updated in the database After the status has been updated in the database. Based on your problem statement, I believe the hook you want is “pre_post_update”, as stated in relevant WordPress source code: /** * Fires immediately before an existing post … Read more