Get the name of menu item with wp_nav_menu

The object_id holds the ID of whatever object the menu item refers to, this will be a post, post etc. The get_queried_object_id() will give you the ID of the current page. $menu_items = wp_get_nav_menu_items( ‘main-menu’ ); $this_item = current( wp_filter_object_list( $menu_items, array( ‘object_id’ => get_queried_object_id() ) ) ); echo $this_item->title;

Displaying list of posts in category page

One option would be to just replace category template with another file from the plugin using category_template filter: function change_category_template( $template ) { $category_template = plugin_dir_path( __FILE__ ) . ‘new-category.php’; return $category_template; } add_filter( ‘category_template’, ‘change_category_template’, 999 ); So, in the new file you could have the structure you want. The main problem is that … Read more

random display categories – change url

As you are concatenating the result to a href you must wrap the ifelse statement inside another set of parentheses so the result is calculated first and then returned: <a href=”‘.(($cat_id == 5) ? esc_url($custom_link) : esc_url($category_link)).'”>

Need help with pagination

$paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1; $args_blog = array( ‘post_type’ => ‘post’, ‘paged’ => $paged, ‘posts_per_page’ => get_option(‘posts_per_page ‘) ); $query_blog = new WP_Query( $args_blog ); if($query_blog->have_posts()) : while($query_blog->have_posts()) : $query_blog->the_post(); $big = 999999999; // need an unlikely integer echo paginate_links( array( ‘base’ => str_replace( $big, ‘%#%’, esc_url( get_pagenum_link( $big ) ) ), ‘format’ … Read more

Filter results from a serialized string to use on statistics

So basically the form saves a large serialized array in the database. Now since you have multiple forms, you need to iterate over the result from get_results, unserialize the column and then access the city key. global $wpdb; $table_name = $wpdb->prefix.’db7_forms’; $results = $wpdb->get_results( “SELECT form_value FROM $table_name WHERE form_post_id = 6062”, OBJECT ); // … Read more

Function Reference/human time diff for future posts

You could also do it using human_time_diff hook, but it would make it global: function my_time_diff_mins( $since, $diff, $from, $to ) { return $since . ($from > $to ? ‘ from now’ : ‘ ago’); } add_filter( ‘human_time_diff’, ‘my_time_diff_mins’, 10, 4 );

How to clone all WordPress Rest API end points

There is nothing wrong if API returns more than what you need. Unless there is a security/privacy issue it is unlikely that the additional info will matter. If you totally can not live with core’s API, you need to just write your own. “cloning”, “forking” or any other nice term you might want to use … Read more

How do I prepare strings for insertions as values into a MySQL table?

dbDelta is really meant for creating databases or tables, not inserting records. I’d suggest using $wpdb->insert(), which will escape the values for you: $wpdb->insert( $wpdb->prefix . ‘w2bw2c_venue’, array( ‘market_id’ => 7, ‘venue_name’ => get_the_title( $id ), ), array( ‘%d’, ‘%s’, ) ); I’ve just used the name field you were having trouble with in my … Read more