New answers tagged

2

You can get the post type object and check it properties. For example: $post_type = get_post_type_object( 'books' ); if( $post_type->exclude_from_search ) { // The post type is not included in search results } if( $post_type->has_archive ) { // The post type has archive } As far I know, custom post types are not included in dates archives ...


0

If you are on the front, on template you can use the is_post_type_archive( $post_types ) conditional tag function. $post_types can be a string or an array of posts types to check against.


0

Use pre_get_posts instead of request: function post_type_tags_fix( $request ) { if ( ! is_admin() && $request->is_tag() && $request->is_main_query() ) { $request->set( 'post_type', array( 'type_one', 'type_two' ) ) } } add_action( 'pre_get_posts', 'post_type_tags_fix' );


0

wp_query has the offset parameter which you can use to skip posts, e.g. $args = array( 'post_type' => 'video', 'tax_query' => array( array( 'taxonomy' => 'tax-video', 'field' => 'slug', 'terms' => 't-o-t-w', ), ), 'posts_per_page' => '8', 'offset' => 1, // excludes the first post in the query ); you may just be ...


0

My first port of call is to call global $post; - as that sets you up to use $post->ID ... if you are using it then the next step is to display each part separately e.g. print_r($tags); echo $first_tag; see what's displayed in each part, this will help diagnose where the issue is, as without seeing your code working, we can't say why it's not working.


0

try This Code Change taxonomy name which you are using /**post type name: brochures **/ /** taxonomy name: brochures-cat **/ <?php $custom_terms = get_terms('brochures-cat'); foreach($custom_terms as $custom_term) { wp_reset_query(); $args = array( 'post_type' => 'brochures', 'tax_query' => array( array( ...


0

To retrieve all the terms attached to your taxonomy "brochure_categories", you can use get_terms() function. More info here. Once you've got your terms, you can traverse them and query your custom posts with: $query = new WP_Query( array( 'post_type' => 'brochures', 'brochure_categories' => $current_category, 'posts_per_page' ...


0

You cant export only categories (or taxonomies generally). Just export all content with Tools/Export and you can delete content except categories from xml.


1

You can call https://codex.wordpress.org/Function_Reference/get_ancestors within your template. It'll return an array of ancestors to your current post and you can use the length of the array to see how deep you are in your hierarchy. Use it at the top of your template file to set a variable $post_depth and use that to adjust your body_class for targeted ...


0

I also have right now same issue. This is not a bug. Ex. If you want to filter 2 different 'custom post type' example 'bed_post' and 'chair_post' by taxonomy 'metal' you can use same name for them. If not use different name. Remember that you can use same slug with different taxonomy name. $furniture->register_taxonomy(array( 'taxonomy_name' => ...


0

$args = array( 'taxonomy' => 'portfolio_type', 'exclude' => '28,30', ); $tax = get_terms($args); foreach($tax as $t){ echo '<div class="span3 produto-lista">'; $args = array( ...


2

Flushing the rewrite rules - which you can do just by visiting the Settings -> Permalinks page - was a good step to take, because it's usually the overlooked cause of these sorts of issues. However as Milo said in the comments, in this case, it's just that the publicly_queryable argument needs to be true if you want these posts to display on the frontend. ...


2

Custom page templates are for pages - not post type archives :) Naming your template file as archive-projects.php will cause Wordpress to select it for your Projects archive page. You also don't need the /* Template Name: Projects */ in there, as this template naming is default Wordpress behaviour. See the visual overview of the template hierarchy to ...


0

You need to use the methods of your query instance, rather than the global functions (which are merely wrappers for the global $wp_query): if ( $query->have_posts() ) { $term = $query->queried_object; while ( $query->have_posts() ) : $query->the_post(); //Output my posts the_title(); the_content(); endwhile; ...


0

As per comments the single view of your CPT will be handled according to template hierarchy. Within appropriate template you can use template tags normally, so simply get_post() without arguments will get you a current instance. It is a little more tricky if you want to refer to a specific post in code outside of its context. The most reliable within ...


2

I think you should be able to do this with the user_has_cap filter. Because that filter passes through the post ID in the $args for the edit_post capability, you can use that to check if the current user has been artificially given this capability - and if so, force the edit_post capability to be true for that instance. Building from the example in the ...


2

There is no order_by. Change order_by to orderby and it should work. The default value of compare is = so it is unnecessary, you can remove it. Also, you should specify type of the meta_value if it is a specific type rather than the default CHAR.


1

You need to query the db using wp_query to get all the posts from the CPT, save the metabox contents to an array and then print the array. Not tested but should work (i hope): <?php $select_array = array(); $args = array ( 'post_type' => 'your_cpt', ); $query1 = new WP_Query( $args ); while ( $query1->have_posts() ) { $query1->the_post(); ...


1

If I get this right each of your posts have one value of Exercise and one Value of Tempo? I would do the following probably: Build a list of exercises. For each exercise query query: 1 posts, ordered by Tempo, descending. This is probably as good as it gets staying within realm of WP API. Might not be practical for high counts of Exercises, it's all ...


1

You first have to build a query for your posts, and inside that query you would get all your custom fields and compare them. You could use a plugin like CMB2 to build repeatble grouped fields so you can get the exercises grouped (all Excercises1, all Excercises2, etc) and also asign each to have a TEMPO field attached to that group. It would be easier then ...


0

Just change 'fields' => 'name' to 'fields' => 'names' If you look at the examples in wordpress documentation you can see you should use plural(names, slugs, ids for fields): https://codex.wordpress.org/Function_Reference/wp_get_post_terms#Examples


0

As an addition to your scripts I wrote the script which hides sidebars from the dropdown list (I couldn't find this anywhere). I made some reverse engineering of the original widgets.js Wordpress code to write this. The complete solution for allowing to drag & drop only to specified sidebars and to filter the dropdown list (you just need to put this in ...


0

I think you already give the answer: use custom post types: define a custom post type per type coming in. Some notes for 2 way syncing: metadata property changes dont change the modification date, which might be handy to verify while syncing. Luckily you can add some callback for this e.g.: Example metadata fields changing > modified date add_action( ...


1

So i found a solution. 'with_front' => bool Should the permalink structure be prepended with the front base. (example: if your permalink structure is /blog/, then your links will be: false->/news/, true->/blog/news/). Defaults to true 'rewrite' => array('slug' => 'uslugi-i-czenyi','with_front' => false), Hope helps somebody


1

Should work 'with_front' => false, 'with_front' => bool Should the permalink structure be prepended with the front base. (example: if your permalink structure is /blog/, then your links will be: false->/news/, true->/blog/news/). Defaults to true function uslugi_init() { $args = array( 'label' => 'Услуги', 'public' => true, 'show_ui' ...


0

I think your issue is with the rewrite portion when you registered the custom taxonomy with posts. 'rewrite' => array('slug' => 'some-slug', 'with_front' => false) You can replace some-slug with anything you would like. It might be possible to replace it with article/event-category to get the results you want. Setting with_front to false removes ...


1

You can make a custom template for a custom post type. Generally I use the single.php file and duplicate it. Then I rename it to single-{custom-post-type}.php as per Post Type Templates. In your case the template file should look like this single-uslugi.php. As far as saving the old URLs and fixing things I don't quite understand what you are looking for. ...


0

You need to add: 'supports' => array('title', 'editor','page-attributes','thumbnail') add this to your array after 'singular name' => 'pictures'. The thumbnail adds the featured image option to your post type. You can access the post type archive: yoursite/archive-pictures, this will use your themes archive.php file if it exists. Or you can ...


1

Hello maybe this can help, i use this kind of query to retrieve cpt query and display contents: <?php // querying Database $args = array( 'post_type' => 'Pictures', 'posts_per_page' => 6); $the_query = new WP_Query( $args ); ?> <?php // creating the loog if ( $the_query->have_posts() ) : while( ...


0

You can use a tax query! This snippet also makes use of wp_list_pluck, a super handy function for "plucking" properties from an array of objects (in this case, getting an array of term IDs from an array of term objects): // Get current posts location term(s) $locations = get_the_terms( null, 'location_taxonomy' ); if ( $locations && ! is_wp_error( ...


1

Because you save your data as appointment-start-date (hyphens), but in your orderby handler you use appointment_start_date (underscores). They need to match! $query->set( 'meta_key', 'appointment-start-date' );


0

Here's a simple solution: /* --------Sortable Events on Dashboard - show start date, time, venue--------- */ /*------------------------------------------------------------------------------- Custom Columns -------------------------------------------------------------------------------*/ function my_*YOUR POST TYPE*_columns($columns) { $columns = ...


5

Just create a "placeholder" menu that you can then assign all your post types to: function wpse_226690_admin_menu() { add_menu_page( 'Events Manager', 'Events Manager', 'read', 'events-manager', '', // Callback, leave empty 'dashicons-calendar', 1 // Position ); } add_action( 'admin_menu', ...


0

Since you are using single values anyway, how about trying just: $meta_SDate = get_post_meta($post->ID,'event_start_date',true); $meta_EDate = get_post_meta($post->ID,'event_end_date',true); Also note the following lines will need a space to separate the posted values so strtotime can work properly: $updStartD = ...


0

Tjena Henrik! I think all you need to do is to add a rewrite rule to the Wordpress Rewrite rules that have already been created. Add this code snippet to your functions.php of your theme or include it as a separate pugin... add_action('init', function () { add_rewrite_rule('visningshus/?$','index.php?pagename=visningshus', 'top'); ...


0

Well just in case anyone else has this issue, my problem was that I was adding a post status of 'published' when I inserted the custom post type, rather than 'publish'. Hand meet forehead.


2

Your condition is off and will always be true on category pages due to how logic operators work. This might be more clear if I write what is happening like this: is_category() || ( is_tag() && $query->is_main_query() ) Once is_category() is determined to be true the rest of condition doesn't matter. You should be more precise with your ...


1

Here is an sample of my plugin's code where I set a custom post type "aei_team_member" and add 2 columns (Prénom and Photo where Photo is a thumbnail) in admin list using : manage_${post_type}_posts_columns and manage_{$post_type}_posts_custom_column Further information can be found here: ...


0

I had a answer in development then I read what you were looking for some more. I will need more info before I can help. Is a reviewer/speaker a custom post type or a user? Is this relationship only going to be displayed on the article. Or will you also be displaying it on the Guest Authors/Speakers page as well?


0

You've tried with meta_query? $rooms = get_post_meta( $post->ID, 'bedroom', true ); $meta_query = array( array( 'key' => 'bedroom', 'value' => $rooms, 'compare' => '=' ) ); WP_Query documentation on custom field parameters


0

You have a date format mismatch here. You say your dates are saved as Y/m/d in your custom field, which is correct, but then you try to match this format to unix timestamp (which is the result from time()). Date and time formats need to be in exactly the same format in order to match or to compare two different dates in a custom field, this is how custom ...


0

If I understand it right your workflow is that you query posts (implicitly via normal WP mechanics), then display data from external database for them, but want to sort based on external data. This isn't trivial (without mirroring you don't want to do), since WP relies primarily on SQL over its own data for sorting. One of the ways you could implement it ...


1

First, we need to declare CPT. Here in example I am creating with the name "command". Also I am adding category and tag support for this CPT. The CPT will be public, searchable, will have archive page, feed page etc. add_action( 'init', 'create_post_type' ); function create_post_type() { $post_array = array( 'name' => ...


0

Figured it out. The Answer: // tax_query needs to be an Array of an Array 'tax_query' => array( array( 'taxonomy' => 'vodka_type', 'field' => 'slug', 'terms' => $type, ), ),


1

You can interfere with save_post action then change menu_order to post_ID: add_action('save_post', function($post_id, $post, $update) { if ($post->menu_order === $post_id) { return $post_id; } else { global $wpdb; $q = "UPDATE $wpdb->posts SET menu_order=%d WHERE ID=%d"; $wpdb->query( ...


2

You've added the following line to arguments: 'taxonomies' => array( 'category', 'post_tag' ),. It will register the same categories and tags to video post type which you're using with default posts. First things first: remove line 'taxonomies' => array( 'category', 'post_tag' ), In order to have a new "exclusive" taxonomy only for video post type, ...


0

Your code looks good. However, you can try the followoing codes to get all custom posts $args = array( 'public' => true, '_builtin' => false, ); $output = 'names'; // names or objects, note names is the default $operator = 'and'; // 'and' or 'or' $post_types = get_post_types( $args, $output, $operator ); ...


0

You can order posts by meta value check out the codex https://codex.wordpress.org/Class_Reference/WP_Query


-1

Remove category from taxonomies it will remove default category from post type. Further, you also want to add taxonomy for your video post type, please refer to this link http://apnagarage.blogspot.in/2015/09/wordpress-portfolio-post-type.html?m=1


0

As @N00b pointed out this can go in many answers and needs many concepts digestion.I will try to concise and give a sample answer with little info. Since you have set has_archive to true while registering post type , we can see all treatment post-type post on example.com/treatment/. If we want to change this page to display just taxonomy categories list, we ...



Top 50 recent answers are included