Tag Info

New answers tagged

0

get_term_by returns an object by default, so you could output the term name using <?php $term = get_term_by('name', 'foo', 'category'); echo "<div>$term->name</div>"; ?>


0

You can use get_terms. In your case, something like this ought to get you started: $term_list = get_terms( 'taxonomy_name', 'hide_empty=0&orderby=name' ); foreach( $term_list as $term ) { echo "<li>" . $term->name . $term->description . "</li>"; }


2

WordPres has a function that extract IPTC info from images, that function is wp_read_image_metadata. That function is only available on admin side and, according with the codex, it doesn't extract IPTC keywords. But you can use iptcparse from PHP at your own to extract IPTC keywords and set them as post tags. In your question, you said that you have already ...


-1

It depends. To extract the IPTC keywords you will have to find a library or a code sample that you can use as I don't remember anything in wordpress doing that. As for using the keywords as tags for posts, in theory it is possible. The main issue with it is that images are not attached to posts in a "hard" way. A post just includes a url of an image so ...


1

You are correct that this is ineffecient, and there isn't really much you can do about it. I think the only other way to do this may be is with a very large (also ineffecient ) custom SQL query which unfortuantely I cannot help you with. If you have like 10 or 20 terms, the impact will not be that big, but if you have more, the effect can get very ...


0

I had a similar problem. The code is good, but it needs to small modify to work. $args = array ( 'term' => $term_id, 'posts_per_page' => -1, 'order' => 'DESC', 'tax_query' => array( array( 'taxonomy' => 'yourtaxonomyhere', 'field' => ...


1

There's a much simplier (and more secure way*) way than hiding the user interface (show_ui=false) and adding a custom metabox to only display terms. If you remove the capability of the user to manage terms, however, not only do you have a secure solution, but user interface takes care of itself. As part of the register_taxonomy() you can specify the ...


0

This code runs "wp_insert_term" only when needed (only when querying for all terms) for better performances register_taxonomy( 'categories', null, array( 'hierarchical' => true, 'labels' => array( 'name' => 'Categories' ), 'show_admin_column' => true, 'show_ui' => true, 'query_var' => true, 'rewrite' ...


2

You can just grab the first post from the main query and see which post type it is: if ( have_posts() ) { $post_type = $wp_query->posts[0]->post_type; } If you run this code directly in a main template file you should be fine, but if it's in a function you will need to call global $wp_query; first.


1

I would suggest querying a list of all post types using get_post_types. With that array you can do a foreach. and for each post type, query all terms with get_term. It would look something like this, but you should pass get_post_types your know post types, because as it stands, this will also display things like attachments and nav menus. function ...


0

The main problem is that, in your $_POST loop, $value is an array, yet you apply htmlspecialchars to it, which will vomit and return back nothing. If you haven't done so already, set WP_DEBUG to true in your wp-config.php - developing without it is simply not an option. Regardless, let's fix that dirty $_POST loop: $tax_query = array(); // Don't need ...


0

This is strange and should not happen by default. get_posts uses WP_Query. If you look at the source code of get_posts, all the parameters passed to get_posts is passed unchanged to WP_Query except parameters like category which is changed to cat, the include and exclude parameters to include or exclude certain posts which is changed to post__in and ...


0

Here you can read an article about how to deal with. You'll have some mandatory things to do such rewrite your taxonomy with the same name of the custom post type. http://someweblog.com/wordpress-custom-taxonomy-with-same-slug-as-custom-post-type/


0

Turns out setting explicity posts per page did if for me.


0

you can name the file in this way: taxonomy-{taxonomy}.php as described in this page, there you can create a loop adn WP will only select the elements of the given taxonomy.


0

Your code is all upside down and scrambled. What you would want to do is to check for a specific term and then feed that into get_the_term_list(), not the other way around. Also, evaluate your switch to true. I would probably first get an array of terms attached to the post and then check if my desired term is in that array to make my statement a bit more ...


1

If you want to apply the required attribute every time you use wp_categories_dropdown, use wp_dropdown_cats filter as suggested in other answers: add_filter( 'wp_dropdown_cats', 'wp_dropdown_categories_required' ); function wp_dropdown_categories_required( $output ){ return preg_replace( '^' . preg_quote( '<select ' ) . '^', ...


1

If you have a look into the function in wp-includes/category-template.php you will see, there is no option for 'required' build in. So we have to choose another way since $args['required'] doesn't work - as you know. We find the filter 'wp_dropdown_cats', which provides us with the output just before the function returns this output. So we could work with ...


1

There's a filter - wp_dropdown_cats (not documented anywhere as far as I know.) It gives you two parameters, the HTML string and an array of the arguments supplied to wp_dropdown_categories, and you need to return the new HTML.


0

try init instead of after_setup_theme function example_insert_category() { wp_insert_term( 'Example Category', 'friendsof' ); } add_action( 'init', 'example_insert_category' );


1

You need to insert your term after the init hook (i.e. when the taxonomy is registered): function create_tax() { $args = array(...); register_taxonomy('custom_tax', array('post'), $args); // Now we're safe $result = wp_insert_term('Test Term', 'custom_tax', array('parent'=>0) ); }


0

if you are using Custom Post Types CPT and I assume you've created custom taxonomy for that custom post type lets say: You have CPType named Products and you have CPTaxonomy named Products Categories If you are trying to display the CPTaxonomy into your products page somewhere in the loop you I would suggest to use this function according WP codex: ...


0

Use CSS, I was implementing the JS solution and I didn't like the delay, then I've remembered about this. body.taxonomy-name .term-description-wrap { display:none; }


0

Use the Switch statement. switch ($term->name) { case 'customtermincustomtaxonomy': // ... break; case 'anotherterm': // ... break; case 'somethingelse': // ... break; }


0

I used: $args = array( ... 'rewrite' => array( 'slug' => 'portfolio-taxonomies' ), ... ); register_taxonomy( 'portfolio_taxonomies', array('portfolio'), $args ); So my URL is predictable. And you did one thing wrong, URL you are putting is NOT correct. If the rewrite rule is implemented, then they would be: ...



Top 50 recent answers are included