Tag Info

New answers tagged

1

There is more generic version of current_user_can() - user_can() which takes user and capability or role to check for. So your pseudo code would become something like: if ( ! user_can( $user_id, 'invisible' ) )


1

For custom post types use is_post_type_archive('tips'). Let us know if this works. It should also work with an array is_post_type_archive( array( 'tips', 'cpt', 'another cpt' ) ) I am currently using this function to recognize specific post type archives. See: A Post Type Archive in codex. It would be best if you could specify which cases the menu should ...


1

I learned from Rarst and S_ha_dum two new nice techniques that I want to share with everybody beginner in coding PHP/Wordpress: Var_dump function is useful to check what is the nature of a variable during the steps of code. geting into the habit of verifying that you have the kind of data you think you have before you try to use that data. For example, ...


0

Sorry for reviving this post, but it was on the front page and I noticed that it's very old too late... Here's my take on this problem: // This will filter the shortcode attributes and will insert custom // value for the "cat" parameter function filter_gmaps_shortcode_atts( $atts ) { // We add a custom value in the $cat parameter if ( is_tax( ...


0

Since 3.1.0, get_ancestors() is available. It returns an array of ancestors from lowest to highest in the hierarchy.


2

If you're using a custom taxonomy, you can't use the_category() -- that's reserved for the default WordPress category taxonomy. Instead use the_terms(): <span class="itemCategory"> <span class="icon-folder-close"></span> <?php echo __( 'Published in ', THEMENAME );?> </span> <?php the_terms( $post->ID, 'status', '', ", ...


1

I'd recommend creating 3 separate ['associated_items'] fields instead of 1. For Example: ['associated_articles'] & "Filter for taxonomy term: Articles" ['associated_presentations'] & "Filter for taxonomy term: Presentations" ['associated_news'] & "Filter for taxonomy term: News" Note: Filtering for the taxonomy term, limits the related ...


1

I don't know which line that error refers to but this code works correctly if everything falls into place exactly right. But there are actually several ways this could go wrong. For example, if get_query_var('author_name') is not set you get an error on this line: $used_terms=list_author_used_terms($user->ID); If a problem occurs here: $terms = ...


0

I ended up adding an additional taxonomy meta class I was then able to use the following to get my phone number: <?php //Get the correct taxonomy ID by slug $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); //Get Taxonomy Meta ...


0

I have copied my plugin file to a new one .php file and deactivated the old one / activated the new one. Then everything worked successfully. I need to mention that I changed the names of the taxonomies from "Kind" to "Stuff" so I suppose there was an error or something in the database.


0

After struggling a little bit, I found a solution writing this: <?php $cat_args = array('orderby' => 'name', 'show_count' => '1', 'hierarchical' => '0','taxonomy' => 'here goes the taxonomy');?> <ul> <?php $cat_args['title_li'] = ''; wp_list_categories(apply_filters('', $cat_args)); ?> </ul>


1

The /location page doesn't exist because WordPress doesn't just make a page based off your URL structure. You can create a "Page" called "location" if you need to show content there. and if you want to list the available terms you have in the location taxonomy you can create a custom page template ex: <?php /** * Template Name: Locations archive * * ...


0

Taxonomies actually do have archive pages like that, in the same way that categories do. You just have to be sure that when you register the taxonomy, that you do so with rewrites enabled and a slug. For example: // Control the slugs used for this taxonomy 'rewrite' => array( 'slug' => 'locations', // This controls the base slug that will ...


0

Something like this should work (I have tested it in a custom template file). <?php $terms = get_terms("name_of_your_custom_taxonomy"); foreach($terms as $term) { echo $term->slug; // you can display term name, description ..... Look at codex to see the parameters $items = get_posts( array( 'post_type' => 'name_of_your_custom_post_type)', ...


2

You say you want to remove the boxes from the post edit screen, not the Post type screen, so assuming that you should be able to register your taxonomy only for the post types you want it to apply to, and avoid this altogether. The example in the Codex registers the sample taxonomy only for the book post type like: register_taxonomy( 'genre', array( 'book' ...


0

Create taxonomy archives, not pages. Create three separate files called taxonomy-kind-websites.php taxonomy-kind-graphics.php taxonomy-kind-programming.php Displaying the items/posts as a list is pretty simple, eg <ul class="my-posts"> <?php while ( have_posts() ) : the_post(); ?> <li><h2><a href="<?php ...


0

Try Posts to Posts Plugin This plugin allows you to create many-to-many relationships between posts of any type: post, page, custom etc. A few example use cases: manually curated lists of related posts post series products connected to retailers etc. Additionally, you can create many-to-many relationships between posts and users. So, you could also ...


0

Creating these links and displaying them on any desired page with a widget or shortcode can be easily done with a plugin called Sub Posts. It's not a free plugin, but it will do exactly what you're asking. You can find more information at www.subposts.com


1

First get a list of the author posts then loop over the each post and get the terms used ex: function list_author_used_terms($author_id){ // get the author's posts $posts = get_posts( array('post_type' => 'custom_post_type_name', 'posts_per_page' => -1, 'author' => $author_id) ); $author_terms = array(); //loop over the posts and ...


1

You want Posts 2 Posts which allows you to create many to many (or one to many or many to one) relationships between post objects -- including custom post types. To related stores and deals you might do something like this... <?php add_action('p2p_init', 'wpse102461_connection'); function wpse102461_connection() { p2p_register_connection_type(array( ...


0

I believe I found the solution here: http://codex.wordpress.org/Function_Reference/wp_set_object_terms wp_set_object_terms( $post_id, $terms, $taxonomy, $append ); wp_set_object_terms( 4, $cat_id, 'example_product_cat'); This is still placed inside of the install.php file. If there is a better solution, please add! Thanks. Roc.


1

You solved this yourself by running a new query, but a new query should not be necessary as @Milo states in the comments to your question. The main query should be doing automatically what your secondary query is doing. I suspect this has something to do with the way you have registered that custom post type, since I am able to duplicate this problem only ...


1

Solution: At the beginning I thought I resolved my problem after creating a new query with the arguments I need. The code I added is: <?php $args = array( 'paged' => $paged, 'post_type' => 'post_type_name', 'tax_query' => array( array('taxonomy' => 'tag','terms' => $term->term_id))); $query = new ...


1

Did you try BulkPress Plugin? Easily add and manage multiple categories, pages, custom taxonomy terms and custom post type posts. Create and reorder terms


0

You have: A rewrite rule that handles the post being in the 5th part A rewrite rule to handle the taxonomy part A rewrite rule to handle the post being in the 2nd or 3rd part isn't in the above list, hence why you get a 404. If we take this rewrite rule: $newRules['basename/(.+)/(.+)/(.+)/(.+)/?$'] = 'index.php?custom_post_type_name=$matches[4]'; // my ...


0

Use get_the_terms( $post, $taxonomy ): $worktypes = get_the_terms( get_the_ID(), 'worktyp' ); var_export( $worktypes ); You can also use … get_the_term_list( $id, $taxonomy, $before = '', $sep = '', $after = '' ); … to get a formatted output. Example.


1

As you point out, if you want separate loops for different post types you'll need to use a separate WP_Query() for post type. In the template you can get the current term (ID) being viewed via: get_queried_object_id() (see source) $args = array( 'post_type' => 'staff', 'tax_query' => array( array( ...


0

try something like this: <?php $taxonomies = array( 'wissen_tags' ); $args = array( 'orderby' => 'name', 'order' => 'ASC', 'hide_empty' => false ); $terms = get_terms($taxonomies,$args); if (count($terms) > 0): i = 0; foreach ($terms as $term): ?> <div class="wissen_tag_list"> <input ...


0

You were so close, all you had to do was find your category ID from the update method. Like so: $instance['exc_equipment_cat'] = filter_var($new_instance['exc_equipment_cat'], FILTER_SANITIZE_NUMBER_INT); Or however you want to sanitize the number coming from the update. And that will give you the category or taxonomy id.


0

IF it were me, I would make "Year" and "Month" separate taxonomies rather than using a hierarchical taxonomy. If you do it that way, here's a good answer to use as a reference. This will solve the "unique slug" issues you'll run into using hierarchical taxonomies.


0

Did you try %%ct_%% ? For me its working when added to post titles.


1

Thankfully I found an easy solution to this problem. When outputting or terms as checkboxes/radios/whatever, we need to change this: <?php checked( true, is_object_in_term( $user->ID, 'YOUR-TAX', $term ) ); ?> To this: <?php checked( true, is_object_in_term( $user->ID, 'YOUR-TAX', $term->term_id ) ); ?> This is from the function in ...


0

That is not valid PHP code. This would be valid: $args = array ( 'size' => 'big', ); $EM_Events = EM_Events::get( $args ); You might want to read about WordPress Debugging.


0

I've had an interesting struggle with this myself. I'm using http://codex.wordpress.org/Function_Reference/get_the_terms http://codex.wordpress.org/Function_Reference/is_object_in_term I had to display category headings and other meta data depending on the presence of taxonomy tags. I got unpredictable results with is_object_in_term checking for an ARRAY ...


0

It will definately not show in custom_1 because you probably must have defined it for custom_2.However, you can define a custom submenu with link same as that of the taxonomy in which the parent link is that of custom_2. Following is what i mean. add_submenu_page( 'edit.php?post_type=custom_1', 'Page Title', 'Menu Title', ...


0

You could use this plugin instead of trying to use the description field. It's very lightweight and uses drag-and-drop ordering on the admin end. Then you just orderby => term_order when grabbing your terms.


0

code function wc_origin_trail_ancestor( $link = false, $trail = false ) { if (is_product_category()) { global $wp_query; $q_obj = $wp_query->get_queried_object(); $cat_id = $q_obj->term_id; $descendant = get_term_by("id", $cat_id, "product_cat"); $descendant_id = $descendant->term_id; ...


1

For question 1, use a custom field when you create the page and use the same template each time. Here is an example using a custom field named house_type. <?php // Template Name: House Type [ ... ] $house_type = get_post_meta( get_queried_object_id(), 'house_type', true ); $args = array ( 'post_type' => 'house', 'orderby' => ...


1

You can try this (based on your unfinished PHP code) if ( is_single() ) { $terms_of_post = get_the_term_list( get_the_ID() , 'my-custom-term', '',', ', '', '' ); $terms_of_post = strip_tags ( $terms_of_post ); single_post_title(); if( $terms_of_post ){ echo ' (' . $terms_of_post . ')'; } } to get this format: Title ...


0

After many efforts I have solved it. But not completely what I want, had to compromise on one thing and passed some separators in between Url. Example: http://sitename.com/separator1/parentatx/childtax/separator2/postname/ And in order to avoid 404 errors in case of pagination and another custom taxonomy. I created some rewrite rules. Here is my code: ...


2

It seems that every time I post a question here I find solution on myself. Sorry for posting. So my solution in problem described above is: just change 'show_ui' to false. 'show_ui' => false, It helped me. Sorry again for posting.


0

Is there any WP built in function which does the right job? No. [Do I] have to write a custom query for that? No. Use get_terms(). Here is an example. Add the wpse_99513_adjacent_category class to the functions.php theme file and call it like this: $category_ids = new wpse_99513_adjacent_category( 'category', 'id', false ); -- 'category' is ...


1

You should use Taxonomy Parameters available in WP_Query. For example, to get the three recents magazine_entry posts having the international term slug, you can use: $args = array( 'post_type' => 'magazine_entry', 'posts_per_page' => 3 'tax_query' => array( array( 'taxonomy' => 'division', 'field' ...


0

I'd be interested to know your opinion on my finished solution. Please feel free to pull me up on anything if it could be done better. Solution is below: <select id="select-category"> <option class="first-option" value="-1">Select Product Category</option> <?php $taxonomy = 'category'; $terms = ...


0

get_page_template returns the template of the current active post/page. You're not on a post/page though, you're in a listing/archive. When you get page.php what you're seeing is the template of the first post/page. The taxonomy listing itself is not a page, it's a listing, and so it makes no sense for it to have a page template, as it is not a page. See ...


0

You are using get_the_term_list which generates an HTML string of taxonomy terms associated with a post and given taxonomy. Try instead to feed the terms input parameters of the WP_Query with an array like: 'terms' => array( 11, 22, 33 ), or 'terms' => array( 'term1', 'term2', 'term3' ), In your code example you have 'terms' => ...


0

I couldn't get the SQL statements to work so I came up with another approach (not the best way to do this, but it works)... <?php $args = array( 'post_type' => 'puppies', 'taxonomy' => 'litter-type', 'term' => 'previous-litters', 'posts_per_page' =>-1 ); $loop = new WP_Query($args); if ( $loop->have_posts() ) : ?> ...


0

When you create permalink structures like /article/%category%/%postname%/, it becomes very complicated when %category% is hierarchical. The problem WordPress runs into is knowing if after the second slash, the next part of the URL is a category or a post. For instance, in the url /article/parent/child/, is "child" a subcategory of "parent", or is it a post ...


0

You would have to JOIN a couple of tables. SELECT meta_value FROM wp_postmeta as pm INNER JOIN wp_term_relationships as tr ON (pm.post_id = tr.object_id) INNER JOIN wp_term_taxonomy as tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id) WHERE 1 AND tt.taxonomy = 'laptop' AND pm.meta_key = 'quantity' I am fairly sure that is right. These things are ...


1

Try 'terms' => $term_value_array instead of 'terms' => array( $term_name ) It looks like the problem is that you use array("'red','green'") instead of the array structure: array('red','green') that you want.



Top 50 recent answers are included