Tag Info

New answers tagged

0

From what I understand you have a loop that displays up to 500 pages. If the page parent = 18219 than you want to query the tags for that page. As far as I know, by default WP does not allow you to tag Pages, only Posts. But let's pretend you have a plugin that allows you to do that... Inside your loop you can check to see if the page has a parent equal to ...


0

Looking at the function update_woocommerce_term_meta(), you would recognize it just uses the wordpress function update_metadata(), which essentially means that woocommerce is using meta values, just like you do in you CPT. With this in mind, I wouldn't think this procedure would slow down your site + your keeping compatibility by using existing functions. ...


1

The simple and quickest solution is showing categories list by using sitemap plugin with short-code. For example this plugin WP Sitemap Page. Install it and place shortcode on page. Second option is create page template for category list. Using wp_list_categories() Thanks


1

To get a list of categories when you visit yoursite.com/topics or even the default yoursite.com/categories (doesn't matter; it's not a link structure related issue) you have to have a template for this. It's like a sitemap. If you want to show a sitemap on your front-end, you'll have to have a sitemap template. In this case, it's a category archive what ...


0

Okay, it seemed that going with more than 1 taxonomy was just wishful thinking. I settled with this: CPT still is 'magazine' Hierarchical taxonomy terms were used instead: Parent: The author name Children: The magazines that each author will publish. With the code below I managed to get a working taxonomy-authorname.php page: <?php $taxonomies = ...


2

You can follow similar approach with get_the_terms. Here is the function. function add_taxonomy_to_single( $classes ) { if ( is_single() ) { global $post; $my_terms = get_the_terms( $post->ID, 'custom-taxonomy' ); if ( $my_terms && ! is_wp_error( $my_terms ) ) { foreach ($my_terms as $term) { ...


0

I just ran into this issue recently. If you are using a Custom List Table (A/K/A WP List Table) within a Meta Box (located on the post edit screen post.php or post-new.php.) The reason you get redirected to the posts listing screen (edit.php) is because you're Custom List Table generates a hidden nonce field, which is also generated by the post.php or ...


0

This question has different answers in this specific Wordpress question, they may be of help: Display all posts in a custom post type, grouped by a custom taxonomy Personally I used this method that worked for me just fine: $terms = get_terms('tax_name'); $posts = array(); foreach ( $terms as $term ) { $posts[$term->name] = get_posts(array( ...


0

Try like this $args = array( 'post_type' => 'movie', 'tax_query' => array( array( 'taxonomy' => 'producer', 'field' => 'slug', 'terms' => 'WarnerBros', ), ), ); $query = new WP_Query( $args ); See more at wordpress codex


0

You can use the Advanced Custom Fields plugin to add a custom field (an image field) to you custom taxonomy group or individual taxonomies.


0

You can use the Advanced Custom Fields plugin to add a custom field (an image field) to your custom taxonomy group.


0

I was/am using the user taxonomy snippet as well. However, I highly recommend not to mix users and posts in one taxonomy. Meaning registering a taxonomy for users AND posts. The wp_term_relationships table just stores an object_id. Once there's a post and a user with the same ID, everything gets messed up because then, the term is assigned to both, user ...


0

You're correct in your approach. If you post your code will be better, but something like this: $args = array( 'post_type' => 'project', 'tax_query' => array( array( 'taxonomy' => 'region', 'field' => 'slug', 'terms' => $region, //set your region ), ), ); $the_query = new ...


0

SOLVED: This is issue was solved by correctly flushing rewrite rules: global $wp_rewrite; $wp_rewrite->init(); //important... $wp_rewrite->flush_rules();


0

This is the working code. You can try with yours $id = get_the_ID(false); $categories = get_the_category(); $parents = array(); $childs = array(); foreach($categories as $cat){ if($cat->parent == 0){ $parents[] = $cat; ...


0

I managed to sort the problem out myself with a fresh set of eyes but thought it would be useful for others if they find themselves with a similar issue in future. If the answer needs tidying please feel free to suggest any edits. I had to edit a few lines of code in order to resolve it but here is the complete block again. Firstly I had to add in an ...


2

I didn't know that I can register a taxonomy for more than 1 CPT/post type! register_taxonomy( 'location', array( 'offer', 'store' ), array( 'label' => __( 'Location', 'themeify' ), 'hierarchical' => true, 'labels' => array( 'name' => __( 'Location', 'themeify' ), ...


0

The issue has been solved. See below for the correct code to display ACF multiple taxonomy links on WooCommerce product category archives. Specifically note the string: $related_terms = get_field('quick_links', $taxonomy . '_' . $term_id); $queried_object = get_queried_object(); $taxonomy = $queried_object->taxonomy; $term_id = ...


3

You can get close to what you want by using the template_redirect hook. function my_custom_search_url_rewrite() { if ( is_search() && ! empty( $_GET['s'] ) ) { wp_redirect( home_url( "/search/" ) . urlencode( get_query_var( 's' ) ) ); exit(); } } add_action( 'template_redirect', 'my_custom_search_url_rewrite' ); Then you can use a URL ...


1

I'm not completely sure that you do actually need get_terms() twice. It looks very ineffecient and overboard. I don't know if you need this for ordering purposes, but still, there are better ways of doing this without hitting the db so hard. One alternative is to make one call to get_terms() and then use usort() to sort your terms by parent. But this is ...


0

If you look at WordPress' available query variables, you will notice post_type. You will need to add that to your URL: $terms = get_the_terms( $post->ID , 'category' ); foreach ( $terms as $term ) { $term_link = get_term_link( $term, 'category' ); if( is_wp_error( $term_link ) ) continue; $term_link = add_query_arg( array( 'post_type' ...


0

I assume you're talking about Custom Post Type, not Custom Taxonomy. Right? If yes, add this code on your functions.php file: function press_this_ptype($link) { $post_type = 'example'; $link = str_replace('post-new.php', "post-new.php?post_type=$post_type", $link); $link = str_replace('?u=', '&u=', $link); return $link; } ...


0

Maybe you can try this: <?php $post_type = 'your_current_post_type_name'; $tax = 'your_taxonomy_name'; $tax_terms = get_terms($tax); if ($tax_terms) { foreach ($tax_terms as $tax_term) { $args=array( 'post_type' => $post_type, // Here you will tell Wordpress only query on this post type "$tax" => $tax_term->slug, ...


1

The second parameter to wp_set_object_terms() takes an array, integer, or string. (array/int/string) (required) The slug or id of the term (such as category or tag IDs), will replace all existing related terms in this taxonomy. To clear or remove all terms from an object, pass an empty string or NULL. Integers are interpreted as tag IDs. ...


2

Implode turns your array like this array( 'Audi', 'BMW', 'Mercedes-Benz' ) into a string separated by the delimiter set in the first parameter of the function, in this case , a comma and a space. In a way you can turn an array into a CSV from this. The result is this: Audi, BMW, Mercedes-Benz. The way WordPress works, it looks for an existing term (within ...


0

You cannot use category slug as its the default slug for WordPress category. Try register your taxonomy with some other taxonomy name like product-category and use taxonomy-product-category.php file to render individual taxonomy category layout(main1, main2 etc.) Function Reference/register taxonomy.


0

This should work for a custom taxonomy. <?php function get_related_posts() { global $post; $taxonomy = 'your_custom_taxonomy'; $terms = wp_get_post_terms( $post->ID, $taxonomy ); if($terms) { $term_arr = ''; foreach( $terms as $term ) { $term_arr .= $term->slug . ','; // create array of term slugs ...


1

the_title() and the_permalink() are functions that automatically echoed. Use in this case get_the_title() and get_permalink(). the code should look something like this: while ( $query->have_posts($post->ID) ) : $query->the_post(); echo '<li><a href="'. get_permalink(). '">' .get_the_title() .'</a></li>'; endwhile; ...


1

From code for post type and custom taxonomy, your CPT is post_features and taxonomy is features. For single post_features, you need to have file named single-post_features.php. For archive, create file taxonomy-features.php. See documentation for detail. https://codex.wordpress.org/Post_Type_Templates Example for single(single-post_features.php): ...


0

Did you remember to flush the rewrite rules after creating your custom post type? Visit Settings > Permalinks and hit save. ( No need to change anything)


1

@Jeff, Thanks for this. I fixed your broken $link function. and changed the defaults to include "»" as the separator. // my own function to wo what get_category_parents does for other taxonomies function get_taxonomy_parents($id, $taxonomy, $link = true, $separator = ' &raquo; ', $nicename = false, $visited = array()) { $chain = ''; $parent = ...


0

No, you cannot create an alias for term names. But if you could, it would not be the optimal or easiest method. Instead of having a single taxonomy were the top level is the OS, the children are the price, and the grandchildren are the app category, instead have 3 taxonomies: Operating System ( iOS/Android/etc ) Pricing ( free/freemium/paid/etc ) App ...


0

Your problem is that you are defining the $typeName variable as an empty array at the stat of each iteration of the loop, effectively erasing it, then filling that empty array with a single term name, which you implode. You don't see any commas because you are implodeing a one term array. Move the definition to before the Loop and the implode to after it. ...


0

Just in case someone reads this after all this time (2011): I ran into the same issue, and after reading many posts, get back to my WP, and 'voila !' : It was working as expected ! this is a cache issue IMHO (WP 4.2.2). Cheers.


0

I added this to my child-theme's functions.php file and it works 100% add_action( 'template_redirect', 'redirect_archive' ); function redirect_archive() { if ( is_tax('location') ) { $termurl = get_query_var( 'term' ); wp_redirect( home_url('/search/location/'.$termurl), 301 ); exit; } }


1

Yes, wp_insert_term() only creates the term. To assign the term to a post use wp_set_object_terms() wp_set_object_terms( $object_id, $terms, $taxonomy, $append ); 


0

I assume location/state and location/state/city are template files. In those 2 template files you should copy the contents of header.php and edit there the title and the meta description. Also delete the request get_header().


0

If I am reading your code and description correctly, you can simplify that to: $taxonomy = 'delivery_option'; $do = get_the_terms($post->ID,$taxonomy); if (!empty($do) && !is_wp_error($do)) { $do = array_shift($do); // assuming a single value as per the description. $term = str_replace('-delivery','',$do->slug); ...


0

As @passatgt stated there are at least 4 actions to hook. Btw the most useful is "delete_$taxonomy" action. The action accepts 3 parameters. To use all of them you have to explicit declare how many parameters you want to receive in the callback function. You can do this by specifing it as 3rd parameter of add_action ...



Top 50 recent answers are included