Tag Info

New answers tagged

2

It goes to the page, but I can't figure out how to modify my loop so it only shows posts that match the current term, in this example "element", nor display the title of the page as "Element". The following arguments for your loop should do: $args = array( 'post_type' => 'design_asset', 'posts_per_page' => 100, 'orderby' => ...


1

Steve, you've asked a couple of questions which I had a look at, and I came to the conclusion that your loop is causing all of your headaches. My loop to display ALL the posts is: $args = array( 'post_type' => 'design_asset', 'posts_per_page' => 100, 'orderby' => 'title', 'order' => 'ASC' ); $loop = new WP_Query( $args ); while ( ...


0

I have managed to find a clean and simple way to achieve printing the taxonomy term assigned to the post with the following: <?php the_terms( $post->ID, 'TAXONOMY NAME', ' ', ' / ' ); ?> Using term retrieves the terms associated with the given object(s), in the supplied taxonomies. Here is a link to the codex with examples and further detail.


0

You should go and read Debugging in Wordpress, as this problem could be easily solved with debug set to true is_taxonomy() was depreciated in version 3.0 already, and has been replaced with is_tax( $taxonomy, $term ) You'll just need to specifiy your taxonomy and term in the parameters and you should be good to go


0

I think you are talking about terms, not categories. You can use wp_list_categories to retrieve and display the terms that a post belongs to. Here is a working example from the codex. Remember the $taxonomy variable can be changed to category or any custom taxonomy <?php $taxonomy = 'YOUR TAXONOMY NAME'; // get the term IDs assigned to post. ...


0

Just like CPT capabilities those of taxonomy are also customizable, in register_taxonomy(): capabilities 'manage_terms' - 'manage_categories' 'edit_terms' - 'manage_categories' 'delete_terms' - 'manage_categories' 'assign_terms' - 'edit_posts' Since your authors only have edit_posts it works as you observe — they can assign ...


0

To follow up on @MZAweb's answer. You can also delete the term automatically like so: add_action( 'before_delete_post', 'cpk_delete_term' ); function cpk_delete_term( $post_id ) { $post = get_post( $post_id ); if ( term_exists( $post->post_title, 'YOUR_TAXONOMY_NAME' ) ) { $term = get_term_by( 'name', $post->post_title, 'YOUR_TAXONOMY_NAME' ...


0

If you say that it's all the same boxes and format anyway, I would create a custom text meta box on the edit page for their posts where they can just type the category (CSS class). That way they have control in the edit page for which category it belongs to at time of writing (or can easily go back through posts and change without any coding knowledge ...


0

$terms = get_terms('location', array('orderby' => 'date', 'order' => 'ASC')); foreach( $terms as $term ) { $args = array( 'post_type' => $post_type, 'orderby' => 'date', 'order' => 'ASC', 'ignore_sticky_posts' => 1, 'post_status' => 'publish', ...


0

According to register_taxonomy() documentation there is rewrite/hierarchical setting which controls that. It defaults to false, which is probably why you don't see it behaving same as native taxonomies.


0

You can try modifying your query using pre_get_posts filter. function mod_query() { if ($query->is_main_query() && !is_admin() && is_search()) { // test print queried search terms print_r( $query->query_vars['s'] ); $search_terms = $query->query_vars['s']; $search_terms = preg_replace('/\s+/', '+', ...


1

If I understood correctly, you want a archive template for terms of core tag taxonomy that includes only your portfolio custom post type. The best way is to use the pre_get_posts action hook to set post_type argument of the query to 'portfolio': add_action('pre_get_posts', 'query_post_type'); function query_post_type($query) { //Limit to main query, tag ...


0

The category objects returned by get_categories() include a property of count: $lc->count


0

I got an answer on WordPress Support forms, http://wordpress.org/support/topic/widget-dropdown-always-displays-first-option?replies=6 Replaced function form with, function form( $instance ) { // Check values $category = isset( $instance['category'] ) ? (int) $instance['category'] : ''; $terms = get_terms( 'app_category', ...


0

The best way is to use Advanced Custom Field plugin. It takes away all the hassle to create the fields, and update them. Procedure could be: 1. Install "Advanced Custom Fields" plugin 2. Create a new field-group 3. Add desired type of field(s) 4. Add this field group to category Now, you can see your added field(s) on the "Add New Category" or "Edit ...


1

You could use the slug of each term as class name (and do the styling via CSS) <?php echo '<div class="col-lg-3 ' . $term->slug . '">'; // $term->slug is the class name echo '<a href="' . esc_url( $term_link ) . '">' . $term->name . '</a>'; echo '</div>'; ?> If you want to use dynamic terms and colors I recommend ...


0

I tried it locally with the permalink setting /%category%/%postname%.php which worked, I have not tested beyond that other than seeing if the other sites open up and they do, but I have a feeling there must be a less hackey way to achieve this.


0

You need to check if books has posts. If it have posts you may create your link. If no then return empty link or so. To check if post type has posts use wp_count_posts() function.


0

For now I've just redirected the default search string (www.sitedomain.com/?s=keyword) to www.sitedomain.com/trade/keyword, (trade is my custom taxonomy) although I'm pretty sure this isn't the correct or best way to do it so it'd be great if someone else has a better solution. Here is the code for redirecting the search string: function redirect_search() { ...


0

Use a new query outside the loop like this one $query = new WP_Query( 'category_name=ben affleck;post_type=post' ); if ( $query->have_posts() ) : while $query->have_posts() : $query->the_post(); // Loop output goes here endwhile; endif;


2

There is no concept of an archive of terms in WordPress. Archives are collections of posts, The Loop only outputs posts. If you want a page listing all terms in a taxonomy, create a page, assign it a custom page template, and output the taxonomy's terms via one of the API functions, like get_terms.


0

I have used my jewelery post type bellows code, You can just replace your post type & taxonomy. Just copy & paste on your functions file. <?php //Register a Jewelry post type. function jewelry_post_register() { $labels = array( 'name' => _x( 'Jewelries', 'post type general name', 'twentytwelve' ), ...


0

I think your best bet would be to setup categories / sub categories. Example: News Counter-Strike StartCraft2 and link them together that way. This will (I believe) especially be much easier when querying your posts, so that you can query from a specific category (ie: Counter-Strike News)


1

Instead of using wp_tag_cloud pls try this in product page <?php $terms = get_the_terms( $post->ID , 'city' ); foreach ( $terms as $term ) { $term_link = get_term_link( $term, 'city' ); if( is_wp_error( $term_link ) ) continue; echo '<a ...


0

I may be missing what you're looking for but you never actually echo the cat_ID in the li and there's no reason to assign $cat->cat_ID to $cat_id. Additionally, I think you could just as well use something like this to get the category id (or ids) to display the current category(ies) of the current post. (using $category[0] will give you the first ...


0

Did you try this? function sort_query($query) if ($query->is_tax() && $query->is_main_query()){ echo $query->query_vars['taxonomy']; $query->set( 'orderby', 'post_title' ); $query->set( 'order', 'ASC' ); //do other stuff } } add_action('pre_get_posts', 'sort_query'); Happy Coding, ...


0

This is probably more complicated than you think, I would look into using a framework: http://wpgear.org/#meta-fields If you want to write your own , here are some decent tutorials: http://net.tutsplus.com/tutorials/wordpress/creating-custom-fields-for-attachments-in-wordpress/ http://sltaylor.co.uk/blog/control-your-own-wordpress-custom-fields/ ...


0

I suggest that you use a shortcode to display taxonomy of your choice : create a class to declare the shortcode and call this function public function shortcode($atts) { extract(shortcode_atts( array( 'data' => 'taxonomy', 'taxonomy' => 'category', //get_terms arguments 'parent' => 0, //only get top level terms by default ...


0

Should be easy enough. First, get the City. <?php $city = get_field('city'); ?> Then in your WP_Query, insert the taxonomy parameter: <?php $loop = new WP_Query( array( 'post_type' => 'member', 'posts_per_page' => -1, 'location' => $city ) ); ?> Et Vilola: you only get the Members that have the taxonomy $city.


0

I found the issue, it's due to feedwordpress, i solved it by turn off Optimize IN clauses thanks for your help


0

If you need just the term names, fetch just the term names: use the field parameter for get_terms(). Build a comma separated list with an and between the last two items with wp_sprintf_l(). // get the term names $term_names = get_terms( 'department', array ( 'fields' => 'names' ) ); // glue the names with comma and an 'and' between the last two echo ...


0

Managed to do it by putting this into the loop: <?php if (has_term( $_GET["lang"], 'sprache' )) { ?> I was then able to creat links like .../autor/steve-perry/?lang=englisch to filter the search results the way I wanted to.


0

your code seems to be correct. Here is the process to debug it: As your code is correct (what I can see), you need to update your htaccess. To perform it, go to the permalinks WP section and save again permalinks (keep your structure). If not working, you need to flush rewrite rules on your function.php template If not working, you need to check the name ...


-3

Add flush_rewrite_rules(); After your register_taxonomy() function


0

Nice one! GhostOne's solution was what I had been looking for. In my situation the custom post type was 'minining_accidents' and custom taxonomies associated with this was 'accident-types' which had multiple terms under it. My idea was to create a custom widget to show list of posts under terms in this custom taxonomies. In my trial run it got what I ...


0

Ok, so I think I've got something for you! As you know, I've had the same issue, and when I was looping through each taxonomy I found that I was generating between 25-35 queries, which is crazy! So I decided to have a go at some MySQL on the term relationships table to see if there was a faster was to query the data. With some help from a great developer I ...


0

I did some coding and I add support of post class, to my plugin called: Custom post types and taxonomies manager In new taxonomy form is option called Post class. Which allows to add category|tag-{slug} and {slug}-{tax_value_slug} to the post class. Download here https://github.com/Pravdomil/wp-custom-post-types-man/archive/master.zip


1

Those are different object types that belong to different tables and hence can have same primary key ID. --> Even though these are different types, all are being stored in one table i.e. wp_posts with post_type = the different types. Check the table structure for clarity. So there won't be any same ID conflict. if we take a look at the functions ...


1

I think your problem lies with the use of get_object_taxonomies( $object, $output ). If you have a look at the codex, the $object parameter should be Name of the post type, or a post object (row from posts) As your code currently stands, you are using the taxonomy name, not post type. If you print $customPostTaxonomies with print_r( ...


2

Strictly speaking, according to the Template Hierarchy, you cannot. Unfortunately taxonomy-$taxonomy-$term-$subterm.php is not provided for in default, so this file structure will not work. The best you can do here is taxonomy-$taxonomy-$term.php So for Thailand you will name your template as follows taxonomy-location-Thailand.php EDIT Just ...


0

$qry->is_main_query() will be true on every main query on your site, front end and admin. You need to add another more specific condition to target only the page you're trying to modify the query on, like is_post_type_archive('trucks').


0

You mean get_the_terms()? <?php $terms = get_the_terms( $post->ID, 'block_type' ); foreach($terms as $term) { echo $term->name; } ?> Or have I simplified this too much?


0

You say your locations are categories, right? So I'ld recommend to have a look at get_posts() to get an array of certain posts. You can pass category as one argument to get_posts. So you'ld only need to get the category of the current post and then put it as an argument of get_posts(). Maybe you'ld have a look at Flexible Posts Widget then as well for ...


0

If you are already on the page of the house (in the loop of the post) you want then something like this should work. I imagine the values are saved as post meta??? If so I had to do something similar and managed to achieve it like this although I'm sure someone out there may have a better way round. $ThisPostID = get_the_ID(); //simply gets the current ...


2

Your problem lies in this line of code in your first piece of code 'category' => $term->name, There are two problems here, first of all, category is not a valid parameter for WP_Query, you should use category_name, as you are working with get_terms. get_terms does not return the ID like get_categories, which is an alternative for the first part of ...


1

See, It's quite difficult to have path like site/books/product_category/horror/ site/movies/product_category/horror/ As wordpress functionality will conflict between custom_post_type & their taxonomy if try to keep url like you mentioned. I suggest you consider the I mentioned below as a solution of your problem. ...


0

Did you post the correct name for the taxonomy template? I think it should be ' taxonomy-listing_category.php. See Custom_Taxonomies_display Or are you including it some other way? With new WP_Query you're not using the default query which has the query variables for the taxonomy and term. You can however add the taxonomy and it's term back to the queries ...


0

When asigning a post to a taxonomy, if you assign it to both a top-level and child term, the top-level will be used in the permalink. If you only select the child, I believe the parent term will be displayed as well. I agree, that this is not ideal and you may be able to work something out with wp_rewrite() but there's an easier way to get the parent term: ...


0

In each foreach loop, you're setting the first item's ID as the value for $selected which will obviously match the ID of the first item. Before running any of the foreach loops fetch the stored value from the DB then use that for the comparison. global $wpdb; $selected = $wpdb->query( "SELECT something FROM $wpdb->table_name" ); // ... foreach loops ...


0

The variable is not working because get_the_term_list returns a string of HTML links, whereas your $args array requires slugs. I'm not sure if you can pass an array of slugs using your current method or not. You can certainly pass an array of slugs using a tax_query array. Incidentally, using your current method, you should be setting the tax name to ...



Top 50 recent answers are included