Give a unique ID while saving

When you add a meta box, the post object is passed to the function that outputs your meta box content, and the ID is immediately available. Here’s a quick proof-of-concept that will put the ID in a field in a post meta box when creating a new post: function wpd_sku_meta_box() { add_meta_box( ‘wpd_sku’, ‘SKU’, ‘wpd_render_meta_box’, … Read more

Using WP meta query to show custom post types by a start and finish date

The query will by default GROUP BY the post ID, meaning that a post will only appear once in the list. You can remove that GROUP BY pretty easily with a filter: add_filter(‘posts_groupby’,’__return_empty_string’); $events = new WP_Query($args); remove_filter(‘posts_groupby’,’__return_empty_string’); That might get you what you want. It is a bit hard to tell. Without the GROUP … Read more

WordPress post carousel

This code is taken from another answer but slightly modified to load your posts from the portfolio post type. This shows you how to load several posts and includes them in a slider. With some modification to the Loop you could out put the first X posts and cycle them using an offset parameter. JavaScript … Read more

Taxonomy rewrite pagination 404

While looking for a solution I got this post: Taxonomies with same slug as CPT So basically you need to add custom rewrite rules, I haven’t tested the solution but I guess it will work out for you. /* Register CPT */ function wpse_138987_post_type_filter() { register_post_type(‘filter’, array( ‘labels’ => array( ‘name’ => ‘Filter’, ‘all_items’ => … Read more

Check category_name or taxonomy slug for a Custom Post Type?

If you’re actually using categories (and not a custom taxonomy) then your $categoryname variable needs to be the slug, not the actual name. Admittedly this Wp_Query argument name is confusing. If, however, you are using a custom taxononomy (and you’ll know if you are) then you should use ‘name-of-your-custom-tax’ => ‘slug’ instead. The codex is … Read more

Let users upload image(s) to the post from front end

wp_insert_attachment returns the resulting post_ID of attachment record created in posts table, so you will need to add these IDs (multiple) in the post meta table using update_post_meta as suggested in code below: $attchmentIds = array(); if ($_FILES) { foreach ($_FILES as $file => $array) { $newupload = insert_attachment($file,$pid); $attchmentIds[] = $newupload; } }; /*The … Read more

Need to have an archive widget which organizes and displays a custom post type using a custom date field

Yep. You can add a meta_query parameter to methods that query posts, such as WP_Query. This one below gets a custom post type between two dates (which are custom fields created by ‘advanced custom fields’ plugin) and sorts on one of these dates: $args = array( ‘post_type’ => ‘event’, ‘posts_per_page’ => ‘-1’, ‘post_status’ => array( … Read more

The loop does not show users

You need to add this code to the file functions.php. function custom_post_author_archive($query) { if ($query->is_author) $query->set( ‘post_type’, array(‘post-type’, ‘post’) ); remove_action( ‘pre_get_posts’, ‘custom_post_author_archive’ ); } add_action(‘pre_get_posts’, ‘custom_post_author_archive’);

Get Terms from Custom Taxonomy and Current Post

You can post the terms by using wp_get_object_terms $terms = wp_get_object_terms($post->ID, ‘departments’); if(!empty($terms)){ foreach($terms as $term){ $exampleName = $term->name; $exampleSlugs[] = $term->slug; } } Alternatively you can try to first ensure that the right taxonomy is being used: $taxonomies = get_taxonomies(); echo ‘<pre>’; print_r($taxonomies); echo ‘</pre>’; If everything is allright you’ll see an array with … Read more