get_posts custom field

If you want to use post meta for setting which posts are displayd on the front page, then I would recommend saving the setting with a separate meta_key. So instead of pushing it to the your_fields save it with its own key. This means modifying your metabox content to have something like this, <input type=”checkbox” … Read more

inserting content of 1 Post to in another with a template hierarchy

Yes, get_page_by_path() will return a post object or array on success, and not the post ID. $faq_post = get_page_by_path( $post_slug, OBJECT, ‘land’ ); // object $faq_post = get_page_by_path( $post_slug, ARRAY_A, ‘land’ ); // array So there is no need to make the custom new WP_Query call, and your code below is good: $faq_post = get_page_by_path( … Read more

How do you determine if a result in a search query is a post or a page?

That will only tell you if it’s a Post or a Page. What if it’s a category, tag, archive, or custom post type? Here’s how I’d write that, if you care. function xyz_get_post_type_name() { $wp_type = get_post_type( get_the_ID() ); switch ($wp_type) { case ‘post’ : $type_name=”Article”; break; case ‘page’ : $type_name=”Web Page”; break; case ‘quote’ … Read more

Show menus to one admin username

function hide_menu() { global $current_user; $current_user = wp_get_current_user(); $user_name = $current_user->user_login; //check condition for the user means show menu for this user if(is_admin() && $user_name != ‘USERNAME’) { //your code here } } add_action(‘admin_head’, ‘hide_menu’);

Need to add onclick javascript at backend of my wordpress site

There are many different contact form plugins. Some of them will store the submitted forms in the WordPress backend. This makes it easy to track the number of submitted forms. An example of a plugin that stores the responses is Happy Forms. Of course there are many others. I hope this addresses your request.

wp_query comment and meta query

The inline documentation of WP_Query has this: Filter results by comment count. Provide an integer to match comment count exactly. Provide an array with integer ‘value’ and ‘compare’ operator (‘=’, ‘!=’, ‘>’, ‘>=’, ‘<‘, ‘<=’ ) to compare against comment_count in a specific way. So there should only be one array, not 2 like with … Read more

Update query for wp_posts and wp_postmeta

The post_id column in the wp_postmeta table is a reference to the ID column in the wp_posts table. I’d suggest using the native update_post_meta() function in WordPress to update the meta data. E.g. (Post ID is 123 in this example, and we’re updating the price to 100.00): update_post_meta(123, ‘_price’, ‘100.00’); Here is the SQL equivalent: … Read more