Tag Info

New answers tagged

0

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); ...


0

wp_trash_post is literal, not dynamic. It doesn't change and always ends in _post regardless of actual post type. See wp_trash_post(): do_action( 'wp_trash_post', $post_id ); You also should retrieve post and check its type from $post_id, do not use globals in that fashion because they might refer to entirely different post. Your second theory refers to ...


0

I think your problem is at the following lines: if ( get_query_var( 'post_type' ) ) $post_type = get_query_var( 'post_type' ); else $post_type = 'job_listing'; Your post_type var will probably already being set, so you are calling some different post type (the one stored inside the query_vars array with the post_type key), which maybe does not ...


0

On a single custom post type (for example), you can see the post meta. However on your homepage archive loop, you cannot because the theme uses a different template for this. Check out Template Hierarchy. The "home" page in _s is governed by the "index.php" template. In which we see: get_template_part( 'content', get_post_format() ); Since there aren't ...


0

i see an error: add_action( 'init', 'create_post_type' ); function create_post_type() { register_post_type( 'testimonial', array( 'labels' => array( 'name' => __( 'Testimonials' ), 'singular_name' => __( 'Testimonial' ), 'add_new_item' => __('Add New Item'), 'edit_item' ...


0

Untested, but I think you'd need to do two separate queries and merge them together: $args = array( 'post_type' => 'featured-posts' ); $featured_posts = get_posts($args); $args = array( 'post_type' => 'review-posts', 'category_name' => 'featured-category' ); $review_posts = get_posts($args); $result = array_merge($featured_posts->posts, ...


0

This includes a custom field named wpsites_textarea. ?> <p><label for="wpsites_textarea" class="screen-reader-text"><b><?php _e( 'Genesis Style Meta Box', 'genesis' ); ?></b></label></p> <p><textarea class="widefat" rows="4" cols="4" name="wpsites_textarea" class="inside"><?php echo esc_textarea( ...


1

Here's an idea: Definitions: Posts per page: PPP Custom post type: Y Main query post type: X How many Y posts to inject each time: y How many X posts to display before injecting the Y posts: x Formula: We will use: PPP(Y) = y * floor( ( PPP(X) -1 ) / x ) where PPP(X), x and y are positive. Examples: Setup 1: PPP(X)=1, x=3, y=2, PPP(Y) = 2 * ...


0

You will need to add your post types in an array. So your code should look like this 'pages' => array('post', 'sfwd-courses', 'sfwd-lessons', 'sfwd-topics'), You should also have a look at this tutorial that I find helpful as well


0

Can't add to takien's post so here's what I ended up having to do: functions.php add_action('init', 'my_year_archive_rewrites'); function my_year_archive_rewrites() { add_rewrite_rule('resource/news/([0-9]{4})/page/?([0-9]{1,})/?', 'index.php?post_type=news&year=$matches[1]&paged=$matches[2]', 'top'); ...


1

I'd add 'has_archive' => true to your arguments array. That turns on archives automatically (with pagination too) for your post type. The template for the post type archive is archive-news.php. Edit For the editable text (sorry, missed the last paragraph), I would either use an option field or a custom sidebar (w/ text widget, I suppose). The amount of ...


1

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( ...


0

Have you tried doing a query on both post types and including the category? I suspect that it will look only for posts in the featured category, then limit by the two post types, but nonetheless it's worth a try. $args = array( 'post_type' => array( 'featured-posts', 'review-posts' ), 'category_name' => 'featured-category' ); $res_posts = ...


0

If I understand you, I believe that the following will do what you need: function orderby_mod_wpse_140999($orderby) { remove_action('posts_orderby','orderby_mod_wpse_140999'); global $wpdb; return $orderby.", {$wpdb->posts}.post_modified DESC"; } add_filter('posts_orderby','orderby_mod_wpse_140999'); $args = array( 'meta_key' => 'premium', ...


0

You must place (delete) some posts in trash bin first to make this options appear. The same with draft. You must first assign some post as "Draft" in edit screen. As I see in your screen, all your PDF CPT are published. So there's nothing in trash, and nothing is a draft.


0

I had this exact same issue, but it's a problem with the Jobroller theme (seeing as the custom post type is job_listing, I'm guessing you're using Jobroller as well). The Jobroller theme adds the custom columns to the job_listing custom post type using the function jr_edit_jobs_columns in the file jobroller/includes/admin/admin-post-types.php: function ...


0

I was looking for another answer and stumbled on this, thought i could help. If you looking to exclude the most recent post(s) you may be able to use wp_get_recent_posts() to retrieve the ID(s), and then use 'post__not_in' => array(#,#) in your WP_Query to exclude those resent posts. Tested this a little and found this to work for getting ONE post to be ...


0

The rewrite value actually comes before your post slug, so you need to visit localhost/wp/realizzazioni/{{POST_SLUG}} to view the post. If your new post's name is "Test" you should be able to view the post at localhost/wp/realizzazioni/test. Other tips: Make sure there isn't a page already using the realizzazioni slug. Finally, flush your permalinks by ...


1

I realize this is an old thread, but I came across it trying to do the same thing and settled on adding a pre-query action using functions.php rather than a template and the loop. In my case; I have a page of about 25 yoga classes, set up as a custom post type 'classes' // function and action to order classes alphabetically function alpha_order_classes( ...


1

There are 3 parts to making this work. Register the post type with correct rewrite slug and archive. We add the %category% rewrite tag to the slug so we can swap in the selected category. We also specify the archive name explicitly. I've omitted the rest of the register_post_type arguments here, the rest can be as-is in your own example. 'rewrite' => ...


5

You can try this: /** * Modify the header title on single pages * but exclude the 'post', 'attachment' and 'page' post types. * * Header Title: Site Name | Post Type Label | Post Title * * Example: My Shopping Site | Products | Sony Playstation 4 */ function wpse_141145_wp_title( $title, $sep ) { if( is_single() && 'post' !== ( ...


2

Try updating permalinks in settings. If that doesn't work please provide the code for your register_posttype function. both the pages are not loaded ...meaning you get 404 errors, or the correct content loads but in the wrong templates? when new post types are added, you will get 404 errors using pretty permalinks until you flush the rewrite rules. ...


0

It sounds like you need to run a foreach on a value inside the array. E.g. $checkboxes['value'] as $checkbox.. If you do: print_r('$checkboxes') you'll get an idea of the values you are trying to target. You might even have to do something like $checkboxes['something']['something_else'] depending on how many levels the array has. Hope it helps, do a ...


0

I have copied your CPT code to my localhost. I had to add register_post_type( 'facebook', $args ); for the CPT to work. Don't know if you forgot to add this piece of code to the code in your question. I also added 'has_archive' => true, as I previously had suggested. I then updated my permalinks, which is set to 'Post name'. I also created two ...


0

I recently did the same using this tutorial: http://www.wpbeginner.com/wp-themes/create-custom-single-post-templates-for-specific-posts-or-sections-in-wordpress If you're looking for an easier option, there's also a plugin for creating post templates: https://wordpress.org/plugins/custom-post-template Hope this helps.


0

After researching s_ha_dum's link and others for a while it seemed like the only way to position meta boxes in between the title and editor fields was to remove and readd the main editor like this, but this feels a bit hacky to me and receives a warning from another answerer about potential problems. I was able to combine @s_ha_dum's method for creating a ...


0

You just need to override the function display_tablenav() with a blank function in you parent class. It is explained here.


0

Thanks Pat J I'have got solution now: <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; ?> <?php $offset = ($paged - 1) * 4;?> <?php $kat = get_field('kategory');?> <?php $query = new WP_Query(array('offset' => $offset,'post_type' => 'modelki', 'taxonomy' => $kat, 'posts_per_page' => '4')); ?>


-1

You're using the argument 'posts_per_page' => '4' in the WP_Query. That is why only 4 posts are showing up per page.


0

This is, what finally fixed it for me: apply_filters('wp_handle_upload', array( 'file' => $file_path, 'url' => $file_url, 'type' => $file_type), 'upload'); Explanation: I'm not quite sure why this fixed the error for me, but I assume that this either has something to do with plugins using the wp_handle_upload hook or that the ...


1

'compare' should be '=' because you are comparing exact values, also 'relation' have to 'AND'. Both should be default, but better to be sure $meta_query = array ( array( 'key' => 'featured', 'value' => 'yes', 'compare' => '=' ), array( 'key' => 'type', 'value' => 'event', 'compare' => '=' ), 'relation' ...


2

In your case you can edit the following code to accomplish what you are looking for by assigning the custom taxonomy meta box to a custom context and then running do_meta_boxes /** * insert meta boxes before main editor below title */ function wpse_140900_add_meta_boxes_after_title( $post ){ // per the comment below filter by post type // ...


1

I believe what you are looking for is the relation parameter in meta_query. I'm assuming you are using the WP_Query class to make the call given your syntax in the example. You might want to ensure that no other plugins are forcing the relation parameter to be "OR" instead of the default "AND" by hooking into pre_get_posts. $meta_query_AND = array( ...


1

You only see ten posts because that is the amount of posts per page set by default in the back end under 'Settings -> Reading -> Blog pages show at most' You can either set that to 14 to display all your 14 posts, or you can use pre get posts or WP_Query to alter the main query/create a custom query to change the number of posts shown on a page.


0

It sounds like you're wanting the page you are redirected to to display the CPT's information in a certain way or format, in which case you'll want to create a single page template for the custom post types you've created. You can use the single.php file as an example for the layout and customize it as necessary, but the name of the file should be ...


2

Filter template_include, check if the current post is a product and load the product template. Example: add_filter( 'template_include', function( $template ) { if ( ! is_singular() or ! get_post_meta( get_the_ID(), 'price', true ) ) return $template; return locate_template( 'product-single.php' ); }); How exactly you determine if a post ...


0

I'm a fan of page templates - Here's what I would do. First create a page called something like Person Gallery, call it whatever you'd like. Then we can create either a separate template page-person-gallery.php or open our page.php and run a conditional in our loop to test if we're viewing the Person Gallery Page: <?php if(have_posts()) : ?> ...


1

Use WP_Query instead of query_posts(). $cpt_args = array( 'post_type' => 'product', 'tax_query' => array( array( 'taxonomy' => 'category', 'field' => 'slug', 'terms' => 'furniture' ) ) ); $cpt_query = new WP_Query( $cpt_args );


0

I assume that the ACF you added to your post type "book" is a "Post Object" with the option "select multiple values" acitvated. So for each book you have, multiple stores can be linked to this one. Here is some code that could help you : <div class="bookdata"> <?php // Get the linked stores // if the ACF is a type "Post Object" and the ...


0

Old question but I found an answer at Here by Simon Hampel at the bottom. Cool filter, but I coulnd't find a whole lot of documentation on it so I'm not 100% sure everything it's connected to. One thing I do know is it's used to pull the links on 'Link to existing content'. Put this in your functions.php file: function custom_wp_link_query_args($query) { ...


0

You can use template_include to set a specific template to a specific types of content using query_vars. Here is a example of how to set a specific single.php called single-information.php to a custom post type called information function pietergoosen_info_template_include( $original_template ) { if ( isset( $wp->query_vars['information'] ) ...


0

I have figured this out. The trick is to use the get_sidebar hook and run some conditionals to check if we're on a CPT page (archive or singular or cpt taxonomy archive) and if the sidebar we've hooked into is the one we want to replace ($sidebar == 'content'). If these conditionals are met we unregister sidebar-2 and add our own sidebar. This probably ...


0

I wouldn't use unregister_sidebar I would copy over the sidebar-content.php file to a plugin and add conditionals to the default sidebar-2 as well as add a new sidebar-4 in that file with the conditional for it. <?php if( is_active_sidebar( 'sidebar-4' ) && is_singular('your-cpt') ) { } ?> <div id="content-sidebar" class="content-sidebar ...


0

pre_get_posts pre_get_posts is used to alter the main query for posts so the is_home() conditional tag will work. You can also use the is_post_type_archive() conditional tag to alter the query on CPT archives like so. add_action( 'pre_get_posts', 'limit_cpt_items' ); function limit_cpt_items( $query ) { if( $query->is_main_query() && ...


0

The first way, using the pre_get_posts action will modify the main query before the page loads. The second way will create a new query. It is much better to alter the main query than to create a new query.


0

You can simply include a custom search function into your search by using pre_get_posts You can do something like this function search_filter($query) { if ( !is_admin() && $query->is_main_query() ) { if ($query->is_search) { $query->set('post_type', 'your-custom-post-type' ); } } } ...


0

Here's what I did. I am using the Advance Custom Fields plugin for the custom fields. I followed the instructions here: http://wordpress.org/support/topic/plugin-advanced-custom-fields-sorting-by-date-picker, which states the easiest way to do this is to compare dates in unix timestamp format. My date field in ACF is called: event_start The date is being ...


0

Your solution (edited incorrectly into the question) should be workable but you should be able to accomplish the same with fewer queries. Pull your portfolio IDs-- note the fields argument. Then pull your attachments with those IDs as the parent post. Then you only loop over the one image array. That works out to two primary queries. To wit: $query = ...


0

You should keep the form on new-customer.php and set the form action to POST to another script (something like new-customer-process.php) and then paste your PHP code into that script. Essentially the user won't know any different as they will be redirected back to the home page. To give you a little more information, the form is what is sending the headers ...


0

To guarantee that your taxonomy is never queried on the front end, you could strip it from all front end queries. add_action( 'pre_get_posts', function($qry) { if (is_admin()) return; $kill = 'genre'; // kill this taxonomy $tax_query = $qry->get('tax_query'); if (empty($tax_query)) return; $relation = false; if ...



Top 50 recent answers are included