Tag Info

New answers tagged

0

I get the query error message. What exactly is the error? Are you using a pre_get_posts filter? Something like: function video_query_post_type($query) { if(is_category() || is_tag()) { $post_type = get_query_var('post_type'); if($post_type) $post_type = $post_type; else $post_type = array('post','video'); ...


1

Please refer below : function disable_new_posts() { // Hide sidebar link global $submenu; unset($submenu['edit.php?post_type=CUSTOM_POST_TYPE'][10]); // Hide link on listing page if (isset($_GET['post_type']) && $_GET['post_type'] == 'CUSTOM_POST_TYPE') { echo '<style type="text/css"> #favorite-actions, .add-new-h2, .tablenav { ...


2

As you guess that's what happening(at least I think). You should separate your ajax logic from your "first load" logic. You can make a function ie my_get_posts that will be called inside archive-work.php and then inside ajax_filter_get_posts you can call the my_get_posts() function. archive-work.php <div class="work-results"> ...


0

You're just echoing the values. If you're wanting to actually create an array with the data in it I think you'll need something more like this. $args = array( 'post_type' => 'locations', 'posts_per_page' => 10 ); $loop = new WP_Query( $args ); $addresses = array(); while ( $loop->have_posts() ) : $loop->the_post(); $zipcode = ...


0

Alright I figured it out! $args = array( 'post_type' => 'vendors', 'order' => 'asc', 'orderby' => 'title', ); $query = new WP_Query( $args ); if ( $query->have_posts() ) { echo '<ul>'; while ( $query->have_posts() ) { $query->the_post(); $category = get_the_category(); echo '<li class="'; echo ...


1

You can use get_field from ACF to check if the field is available and according to the documentation how you conditionally check if a field has contents. <div class="wrapper"> <?php if (get_field('discount')) { ?> <p>Discount: <?php the_field('discount'); ?></p> <?php } else { ?> <p>Price: ...


0

You'd use roles for this. You'd create a new role that has the required access and then assign anyone you want to be in that role 'group'. The User Role Editor plugin should give you the functionality you need to create the access you require.


1

There isn't a single hook for both, the new post page is admin_head-post-new.php.


0

You'd probably be better served by creating a custom taxonomy to accompany your custom post type. That way you can manage terms separate from the built-in categories taxonomy. // Register Custom Taxonomy function wpse_168762_create_gallery_taxonomy() { $labels = array( 'name' => _x( 'Gallery Categories', 'Taxonomy ...


0

This link might be useful in solving your problem: http://3.7designs.co/blog/2014/08/restricting-access-to-custom-post-types-using-roles-in-wordpress/


1

You can pass boolean false to supports to have post type support nothing at all. However note that: you might run into issues with saving "empty" posts (not having one of title/editor/excerpt) likely you still want it to support custom-fields at least, rather than nothing at all


1

The code in question works and I can only think of two reasons why it fails Wrong taxonomy name supplied The terms assigned to taxonomy is empty I would suggest that you get wp_list_categories() working as it is faster and less resource intensive than get_categories() To get empty terms, simply add the hide_empty parameter to your arguments and set it ...


1

Just use 'hide_empty' and set it to false as it's true per default. wp_list_categories( array( 'hide_empty' => false, ) );


0

I noticed that you haven't connected your custom post type and taxonomy completely. I'm not sure if this is causing your current issue, but it would be the first thing I would try. From the Codex: When registering a post type, always register your taxonomies using the taxonomies argument. If you do not, the taxonomies and post type will not be ...


1

I managed to sort this using: <?php $category_ids = get_all_category_ids(); ?> <?php $args = array( 'orderby' => 'slug', 'parent' => 0, 'taxonomy' => 'servicecats' ); $categories = get_categories( $args ); foreach ( $categories as $category ) { echo '<li><img ...


0

step 1: paste below code in your function.php (change the post_type) function house_a() { $args=array( 'post_type' => 'house_a', 'post_status' => 'publish', 'posts_per_page' => -1, 'caller_get_posts'=> 1); $my_query = null; $my_query = new WP_Query($args); if( $my_query->have_posts() ) { $returnvariable=""; while ...


0

I have to do similar things all the time. You are already using ACF, which is what I use, actually I use ACF5 Pro version now, but the same thing can be achieved using ACF4 and the Options Page add on. What I do is create an options page for each post type and set the parent of is so it appears as part of the fly out for the post type. Then I create custom ...


1

I would say that you need to also create a custom taxonomy if you want it to be limited to the one post type. "Categories" is already connected to posts by default. From the WordPress Codex function people_init() { // create a new taxonomy register_taxonomy( 'people', 'post', array( 'label' => __( 'People' ), ...


1

You can use the remove_submenu_page function after registering the taxonomy. This is how it works by default, it has 2 required parameters, the $menu_slug (these are the parent menus e.g. posts, media, pages, comments and so on), and the $submenu_slug (these are the children of those menus) which is what you're removing because your custom taxonomy will ...


0

Never mind I got it. I used <?php the_ID(); ?> to set unique id's but even so that was not the problem. Turns out the first accordion had a class of "in" so the real question was How can I only give a class to the first post of a loop? and I did that by using a simple counter. <?php $c = 0; ?> increment it at the end of the loop then give a ...


0

Try The code below. In your code, the collapseOne was repeated throughout the loop. I added $i as counter and set it as id and href link <?php get_header(); ?> <?php $args = array( 'post_type' => 'question' ); $the_query = new WP_Query( $args ); ?> <div class="wrap"> <div ...


2

EDIT From your comments, I have reworked the entire solution. I'm keeping the original answer just for reference If I have 3 sticky posts, shouldn't they be the first 3 posts on the first page, regardless of their post date? What's happening is that only the sticky posts that happen to be in that first set of 10 posts based on their date are treated as ...


1

When you register your taxonomy, set the slug parameter of rewrite to your desired structure: register_taxonomy( 'custom_tax', 'custom_post_type', array( 'rewrite' => array( 'slug' => 'your-cpt-slug/category' ), // your other args... ) );


-2

$labels = array( 'name' => _x( 'Categories', 'taxonomy general name' ), 'singular_name' => _x( 'Category', 'taxonomy singular name' ), 'search_items' => __( 'Search Types','SkyDance' ), 'all_items' => __( 'All Category','SkyDance' ), 'parent_item' => __( 'Parent Category','SkyDance' ), 'parent_item_colon' => __( 'Parent ...


1

Completely untested but I just threw this together: $post_data = array ( 'comment_status' => 'closed', 'ping_status' => 'closed', 'post_author' => $author_id, 'post_name' => $slug, 'post_title' => $title, 'post_status' => 'publish', 'post_type' => ...


0

Thank you for answering!. I was looking for a more complete solution. I figured it out. echo '<div class="row profiles">'; $terms = get_terms("clinical-programs"); if ( !empty( $terms ) && !is_wp_error( $terms ) ){ foreach ( $terms as $term ) { //View faculty member by clinical programs ...


1

The else in PHP goes at the end of the if statements closing bracket, look at the following: if( 1 == 1 ) { echo 'true!'; } else { echo 'false.'; } So you code would look something like this: <?php $posts = get_posts(array( 'post_type' => 'retail_units', 'orderby' => 'date', 'order' => 'ASC' )); ...


-1

I found the solutions for this, finally i filtering the custom post type by custom type no need to create or converted post type to taxonomy :)


-2

When you get into the loop on the archive page, you can do this : if(have_posts()) { echo found_posts() . " total posts"; } while(have_posts()) { // display each post }


1

In your taxonomy archive template, just add the following: At the top: global $wp_query; Then to get the post count for the entire term: echo $wp_query->found_posts This will display all posts in the query, which in a taxonomy template will be all posts attached to a term. WP Query Codex


2

SIDENOTE: This function can be used even if have posts belongs to one taxonomy only. You don't need to have a post that belongs to two or more taxonomies within the same hierarchy. I have made this function very flexible It is always a problem for me to display a category list or term list for a post if the following conditions occur Having a post having ...


0

I accomplished this by first hooking into the 'current_screen' action and making a determination if my post_type was set, then adding the filter. There may be a shorter way but this works if you need to change the text only on a given post type. public function set_featured_image_filter(){ $screen = get_current_screen(); if( ...


0

Ah I did not use the custom taxonomy NAME which is "resource categories", an apparently those can contain spaces because this worked: $args = array( 'suppress_filters' => false, 'numberposts' => 3, 'post_type' => 'resource', 'resource categories' => 'recruiting' );


0

What is your Custom Taxonomy name? Try the following code, replace taxonomy_name with whatever your actual taxonomy name is. $args = array( 'suppress_filters' => false, 'numberposts' => -1, 'post_type' => 'resource', 'tax_query' => array( array( 'taxonomy' => 'taxonomy_name', 'field' => ...


0

The functions you have tried are for terms by themselves, just existing in site. What you are looking for is get_the_terms(), which retrieves terms of specific taxonomy, assigned to specific post.


0

list all the PAGES that are assigned to particular page(s). I'm assuming you mean "particular term(s)." which would be in your clinical-programs taxonomy. You'll have to do a bit of coding - you need to start a new WP_Query and structure your query as such: $taxPages = new WP_Query( array( 'post_type' => 'YOUR_POSTTYPE_HERE', 'clinical-programs' ...


1

You could also create a template tag like what the Twenty Fourteen default theme includes rather than hard code it into the single file. if ( ! function_exists( 'twentyfourteen_post_nav' ) ) : function twentyfourteen_post_nav() { // Don't print empty markup if there's nowhere to navigate. $previous = ( is_attachment() ) ? get_post( ...


2

You will need to add %link to the first parameter ($format) of next_post_link and previous_post_link This will generate the html links to the respective posts EDIT 1 Just on your statement about custom queries, did you had a look at how pre_get_posts can be used to alter the main query as needed. It is never a good idea replacing the main query with a ...


0

Please, read 2 ADVICES: for example, you want to have(like category) such permalink structure: /new_cars/ferarri/2-doors /new_cars/mercedes/2-doors /new_cars/mercedes/2-doors/my-post1 (unique or duplicate slug names doesnt matter in this case) ...... At first, you may need to set permalinks to /%category%/%postname%. then... METHOD 1: you can register a ...


0

I was searching about the same problem. Have a look at this article. You will find it useful. It might be late for you but may be others get through this.


1

Probably you can achieve this easily with the plugin you mentioned, Advanced Custom Fields. But if you can code a bit, there is a way to easily implement this with no plugin. You can create a metabox with custom fields and attach it to the homepage custom post type, if that's how you have it set up, or to the page that's assigned as the front page for your ...


0

First of all, get all term slugs from the custom taxonomy space by current post ID. $space_terms = wp_get_post_terms( $post->ID, 'space' ); if( $space_terms ) { $space_terms = array(); foreach( $space_terms as $term ) { $space_terms[] = $term->slug; } } You should specify the logical relationship between each inner taxonomy array when there ...


0

You should NOT use flush_rewrite_rules when you register your custom post type. Doing so means you will flush permalinks on every page load. Instead you should use the register_activation_hook. Re the template issue: Try renaming the template to single-dossier.php And try changing your register_post_type array to this: register_post_type( 'dossier' , ...


0

I'm not sure why you're getting the '0's. But you shouldn't be using 2 switch statements in work_custom_columns(). Try this: function work_custom_columns($column){ global $post; switch ($column){ case "work_category": echo get_the_term_list($post->ID, 'work_category', '', ', ',''); break; ...


1

Try This code <?php echo '<ul class="nav nav-tabs" role="tablist">'; $args = array( 'hide_empty'=> 1, 'orderby' => 'name', 'order' => 'ASC' ); $categories = get_categories($args); foreach($categories as $category) { echo '<li> <a href="#'.$category->slug.'" role="tab" data-toggle="tab"> ...


1

Looks like we both missed the error because I didn't see it at first either. In your call to add_meta_box you skipped the argument for context and went straight to priority. "high" is not an available string for the context argument, and this apparently causes the function to silently fail. Adding in the string for context fixes it: add_meta_box( ...


1

I suggest just making a new Post Type with the default Wordpress register_post_type(). function create_my_post_type() { $labels = array( 'name' => __( 'Providers pricing', 'myplugin_namespace' ), 'singular_name' => __( 'Provider pricing', 'myplugin_namespace' ), 'menu_name' => __( 'Provider Pricing', ...


0

I think you're doing this overly complicated. You already have the according $post, so just pass its ID to your function. Try it like so: function intercept_all_status_changes( $new_status, $old_status, $post ) { if ( $new_status === 'publish' && get_post_type( $post ) === 'tweet' ) { // Post status changed ...


0

If you do something like: $custompost = get_post(get_the_ID()); echo $custompost->post_title; You'll find it works. There's clearly a bug somewhere inside the Wordpress core - this is happening to me too for a custom post type. Not sure what triggers it, but the above is a workaround.


2

To change the mode URL variable but in the load try this: add_action( 'load-edit.php', 'my_default_posts_list_mode' ); function my_default_posts_list_mode() { $post_type = isset( $_GET['post_type'] ) ? $_GET['post_type'] : ''; if ( $post_type && $post_type == 'my_post_type' && !isset( $_REQUEST['mode'] ) ) $_REQUEST['mode'] ...



Top 50 recent answers are included