Tag Info

New answers tagged

0

Okay thanks for all the helpful comments. It turns out there is no way to do this using WP_QUERY alone. The best way I can think of is to do it is like so: $taxIds = get_terms($options['post-types'][$this->current_post_type->name], array( 'fields' => 'ids', )); $uncategorisedQuery = new WP_Query( ...


0

How about creating those categories Cars, Tvs, Trains and Ships as sub categories of locations? Then you could have a navigation menu containing parent categories i.e Briton, Manchester etc. Once a parent category is navigated to you could have a menu that uses the get_terms() function with the parent argument set to the current location term ID that lists ...


0

I solved this problem by putting everything into the init call and then calling a check on the tax.. to see if it was empty. I'm not convinced that this is the most elegant solution or efficient so maybe someone will correct or confirm what I have found as a solution.


0

First Assumption: That an extra slash was being added for some reason To see what was going on, I wanted to see what was going on in the array. When I print_r() the array I get the following: Array ( [10] => stdClass Object ( [term_id] => 10 [name] => Mozilla [slug] => mozilla [term_group] ...


0

It turns out the issue here is the foreach statement. I changed the loop from foreach ($taxonomies as $taxonomy) { to for ($counter=0; $counter < sizeof($taxonomy); $counter++) { as well as all relivant itirators so.... register_taxonomy( $taxonomy->singular_name, 'book', $tagArgs ); became register_taxonomy( $taxonomy[$counter]->name, ...


1

You can use the parent argument in get_terms() to get direct children of a term. You can use the child_of argument to get all descendents of a term. Something like this. $parent_id = 32; $args = array( 'parent' => $parent_id ); $terms = get_terms( $taxonomy, $args ); print_r( $terms ); If you want to programmatically get parent terms and within ...


0

Untested, but something like this should work. $siteurl = home_url('/'); $tax = 'region'; // slug of taxonomy $terms = get_terms($tax); foreach ($terms as $term) { $id = $term->term_id; $slug = $term->slug; $description = $term->description; $image_url = z_taxonomy_image_url( $id, NULL, TRUE ); $link = "<a ...


0

Considering the comments and wasting a few more hours searching for a solution I came to the conclusion I have to review my plugin design. There are two promising approaches: Using a template file and provide a fallback. Providing a "shorttag" generator and make the user to create a post / page for each needed category. Thanks for your participation and ...


0

Assuming the position field is filled with numbers to give order: have a look at ksort. <?php $terms = get_terms('brands'); // Let's create our own array and then reorder it $order_terms = array(); foreach( $terms as $term ) { $position = set_up_the_position_meta_here; ...


2

This maybe old, and possibly even at the time of the original question not available but.. If you look in wp-includes/taxonomy.php there is a show_in_menu option for the register_taxonomy() hook that was left out of WordPress's documentation. show_in_menu - Whether to show the taxonomy in the admin menu. If true, the taxonomy is shown as a submenu of ...


-2

<a href="<?php echo esc_url( home_url( '/' ) ); ?>team-names/<?php echo $term->slug; ?>" >


1

With the below, you are grabbing terms from the event_category taxonomy Note that you are always grabbing the same terms though. $terms = get_terms( 'event_category', array( 'orderby' => 'count', 'hide_empty' => true ) ); If you want to grab only from the current pages children, then you should grab the current term ...


1

After some research I have found a blog who actually had an answer to this problem. Here is the function along with the blog url. function taxonomy_slug_rewrite($wp_rewrite) { $rules = array(); // get all custom taxonomies $taxonomies = get_taxonomies(array('_builtin' => false), 'objects'); // get all custom post types $post_types = ...


0

I think your main issue here is the rewrite for your taxonomy. As it stands, your rewrite for the taxonomy looks like this 'rewrite' => array('slug' => 'products' ) This is what exactly what this rewrite means in your custom post type. The following 'rewrite' => true, translates to this in your custom post type 'rewrite' => array('slug' ...


0

I'd recommend at least two things: Change the priority for your products_create_taxonomies action to at least 1, if not 5 or higher. (I'm thinking 0 is not valid for action priorities for some reason) Add your post type creation into an init action just like you did your taxonomies at an earlier priority than your taxonomy (since you are connecting them ...


0

maybe, that post has the parent postID(check their parent post ID's). I doubt,their parent post doesnt exist, and when wordpress tries to get the permalink (with included slugname of its parent),then it adds only the empty slash.


0

Yes it is possible. One part of my question is answered here and full code I will type here. I have larger function wich checkes post taxanomy (in this case custom categories for custom post type). Then we check is there particular taxonomy and we change URL structure. add_filter('post_type_link', 'replace_link', 1, 3); function replace_link( $link, $post ...


0

i use pre_get_posts. example: add_action('pre_get_posts','search_filterr');function search_filterr($query) { if ( !is_admin() && $query->is_main_query() ) { if ( $query->is_search ) { //$query->is_category or etc...except is_page() $arrs[]='post'; $arrs[]='page'; $arrs[]='my_carss'; ...


0

Sounds like you're looking for the NOT IN value of the operator argument of a tax_query. Depending on your situation, you should use either WP_Query or pre_get_posts. Your tax_query would then look something like this: 'tax_query' => array( array( 'taxonomy' => '{your taxonomy slug}', 'field' => 'slug', 'terms' => ...


0

Ok, so I'm feeling generous and will add another answer :) This code will run every time a post is created or updated, and it will add a term to your teacher taxonomy with a name that is the same as the post title. add_action('save_post', 'my_create_teacher_term_from_post'); function my_project_updated_send_email($post_id){ /** Ensure that this is not ...


0

I'm not familiar with woocommerce, but in general, taxonomies are registered via the init hook with a priority of 1 or default priority which is 10 Your code is fine, so I suspect that your priority is wrong here. In short, you are trying to add the taxonomy to the post type before the taxonomy even exists. Try adding a priority of 11 or higher. This would ...


0

You have a couple of issues here looking at your code and tags used to tag your question show_posts is wrong. It is depreciated in favor of posts_per_page. Also, it should be showposts. You cannot use showposts and posts_per_page together. You should only use posts_per_page Don't use camelcase in you custom post type names, they are really problematic when ...


0

I'd suggest that you take a look at the Posts 2 Posts plugin. This plugin allows you to create a link between posts of any type. For example - p2p_register_connection_type(array( 'name' => 'courses_to_teachers', 'from' => 'course', 'to' => 'teacher' )); You'll then have an additional box when editing a post of either type - ...


1

If using get_the_terms, you can just do your if loop once for each taxonomy and then join them after the three loops. Of course, it would probably be more efficient to use: wp_get_post_terms( $post_id, $taxonomy, $args ); You could then do something like: wp_get_post_terms( $post_id, array( 'resource_roles', 'resource_media', 'resource_theme' ) ); ...


1

Ive run into things similar from time to time. What I've ended up doing when using custom post types and taxonomies is the following: Setup a callback on init (before 10) to register taxonomies. Setup another on init (before 10) to register post types. Setup another on 10 to relate them, maybe later if working with other peoples custom taxonomies and post ...


0

in your post loop. use this code. <?php while (have_posts()) : the_post(); $post_type = get_post_type(get_the_ID()); if($post_type !='post'){ get_template_part('content-' . $post_type, get_post_format()); } else { get_template_part( 'content', get_post_format() ); ...


1

get_terms returns an array of objects. You cannot echo an array, if you do, you will just get Array(). What you can do is print_r($array) or var_dump($array) or echo json_encode($array) to see the data it contains. Otherwise, to get single elements, e.g. the name, from the objects, you need to pass $tax_terms through a foreach loop to get the objects from ...


1

I solved it. SOLUTION: <?php if ( has_term( 'downloads', 'listen', $post->ID ) ) { get_template_part( 'templates/content-downloads-vergriffener-baende' ); } elseif ( has_term( 'untersuchungen', 'listen', $post->ID ) ) { get_template_part( 'templates/content-untersuchungen' ); } elseif ( has_term( 'studien-materialien', 'listen', ...


0

It is too specific of a condition for there to be a native way. On other hand this is hardly complicated as simply sorting an array in PHP. You can use usort() with a small custom callback, containing your comparison logic.


0

This could be easily accomplished using the plugin Advanced Custom Fields which allows you to easily create relationships between custom post types. However if you don't want to use the plugin, you can also create the metaboxes yourself. Create a custom post type for Productions Create any necessary custom fields for Productions Create a custom pos type ...


0

First thoughts - a custom tax for actors might work. The Taxonomy Images plugin will make adding the headshot easy. I'd maybe make the production a post - or an instance of a CPT - I wouldn't mess around with CSVs at all. You'd build the table in the post. I would perhaps create a shortcode that you could add into this table, which would generate a link ...


1

Using your current code: $tax_slug = get_query_var( 'event-categories' );


1

<?php $taxonomy = 'judges'; $tax_terms = get_terms($taxonomy); ?> <ul> <?php foreach ($tax_terms as $tax_term) { echo '<li>' . '<a href="' . esc_attr(get_term_link($tax_term, $taxonomy)) . '" title="' . sprintf( __( "View all shows for %s" ), $tax_term->name ) . '" ' . '>' . $tax_term->name . '(' . $tax_term->count . ...


1

First off, I'd like to note a few things wrong with your Post Type and Taxonomy set up. There's a few settings in your $labels that don't make sense: $labels = array( ... 'post_type' => 'attachment', 'post_parent' => $post->ID, 'post_status' => 'inherit', 'post_mime_type' => 'image', ); These last 4 options ...


0

For the record I found an answer to this question in the end - I needed to use a meta query rather than a taxonomy query. The correct code ended up being this: $relatedBlogPostArgs = array( 'post_type' => 'post', 'post_status' => 'publish', 'posts_per_page' => 1, 'order' => 'DESC', 'orderby' => 'date', 'meta_query' ...


1

If you'r using ACF plugin you should look the documentation first, here's relevant ACF saves taxonomies terms meta to options table, and they can be accesed using get_field( "{$field_key}", "{$term->taxonomy}_{$term->term_id}" ); So in you'r example it would be: $image = get_field( 'featured_image', 'product-category_' . ...


0

I added a rewrite rule manually. add_rewrite_rule('^bar([^/]+)(/[0-9]+)?/?$','index.php?bar=$matches[1]','top'); right after add_action('init', 'register_taxonomy_bar'); in functions.php. But Wordpress is SERIOUSLY DENSE in translating /bar/foo/ to barfoo?bar=foo and I don't know how to get around this nonsensical "barfoo" in the path. I also have ...


0

According to user Otto, who provides a good explanatory answer to a similar question, you can safely call wp_get_post_terms() a number of times because Wordpress's internal query caching system is primed before the loop begins, and subsequent calls to wp_get_post_terms() will hit the cache rather than the query: Post meta information is automatically ...


0

Ok, resolved this. I am now registering the taxonomy and terms on the init hook rather than wp_loaded and that seems to have fixed things. I will accept this answer as soon as I can.


1

this tutorial will definitly solve your problem http://en.bainternet.info/wordpress-taxonomies-extra-fields-the-easy-way/ Yes i have used it to add feature images to the custom taxonomy terms.It depends how you registering the custom post .If you have registered the custom post as plugin from plugin directory , then you need to paste ...


1

What you have should work in principle. Note that taxonomies argument needs existing taxonomy, that is one that is already registered at the time you are registering CPT. If the timing is problematic to get right during registration, you could also use register_taxonomy_for_object_type() to create association between the two separately from registration ...


0

I was able to make a 'quick' fix for this issue. The taxonomy we used is hierarchical, this was causing the edit tags and edit posts page to be very slow. Since it was a custom taxonomy where users are not allowed to edit the taxonomies or add new ones we decided to import the hierarchical taxonomy and once in the system register it as a non-hierarchical ...


0

amritanshu you not add id $my_meta->addText('text_field_id',array('name'=> 'My Text ')); 'YOUR-FIELD_ID' Print Command JUST add that line $saved_data = get_tax_meta($term_id,'YOUR-FIELD-ID'); echo $saved_data;


1

You can get the current term slug from the global query. You could do something like this: if( is_tax('cars') ) { //We are in "cars" taxonomy archive page, now get the queried term $term = get_query_var( 'term' ); show_post($term); }


1

$albumGenres = get_the_terms( $post->ID, 'discography_album_label' ); foreach ( $albumGenres as $albumGenre ) { echo $albumGenre->name; // or whatever value }


1

Archive pages A & B already exist as your brand and type term archives, you can style those differently by creating taxonomy-brand.php and taxonomy-type.php templates. The remaining piece is two different single product views. The simplest way to achieve that would be to append a GET var onto the permalinks: ...


1

Well, I’d like to expose my experience in sorting custom post types by category/taxonomy. THE WEB A travel agency web site running on WordPress Main content on custom post type called ‘ruta’ Taxonomy with this structure Type-of-travel > continent >country THE CASE In archive category list pages, the client wanted the posts to be sorted by The ...


0

You can get terms by posts with this functions. $term_list = wp_get_post_terms($post->ID, 'my_taxonomy', array("fields" => "ids")); And echo or use different with foreach(). This tip get terms with ID. You can get another properties. wp_get_post_terms() in codex. Get term by id and taxonomy => $term = get_term($term_id, 'my_taxonomy'); Get term ...


1

You can use following code in the custom post type listing template <?php the_terms( $post->ID, 'custom_taxonomy_name' , ' ' ); ?>


1

This turned out to be a quite extensive little project for me. BASIC IDEA My approach was to go with a custom archive page as this seems to be the best approach here. The thing with custom taxonomies is that if you have a structure in place, changing that would become a real messy expedition. Also, I always try to stay away from custom queries if ...



Top 50 recent answers are included