Tag Info

New answers tagged

0

number_posts is not a valid parameter, it should be numberposts. You should also just use either numberposts or posts_per_page You should also include a check (!is_admin()) in your query to check whether you are on the front end or back end as pre_get_posts alters back end queries as well Rewrite your code to the following: function ...


0

Ooh, thank's for the advices and help (Robert + Peter). The Term confused myself :) This worked for me: $taxonomies=get_taxonomies('','names'); wp_get_post_terms($post->ID, $taxonomies, array("fields" => "names"));


0

Try get_the_term_list <?php echo get_the_term_list( $post->ID, 'taxonomy', '', ', ' ); ?> You can use this in loop. Also, change taxonomy in above code with yours.


0

Ok I've finally figured it out so I will post the answer to my very own question for anyone who might be looking for the same thing. <?php print apply_filters( 'taxonomy-images-list-the-terms', '', array( 'after' => '</div>', 'after_image' => '</span>', 'before' => '<div class="my-custom-class-name">', ...


0

The main query has a loop counter build in which you can access via $wp_query->current_post. This counter starts at zero, so you would most probably add one to that count, something like $wp_query->current_post + 1 Also, you don't need to separately count posts, that is also an already build in function which you can access with ...


1

I found an answer to this at http://wordpress.stackexchange.com/a/105079/40536 I modified my code to the following: <form action="<?php bloginfo('url'); ?>/" method="get"> <?php $term_id = 279; $taxonomy_name = 'categories'; $termchildren = get_term_children( $term_id, $taxonomy_name ); $children = array(); foreach ($termchildren as $child) ...


0

I'm not familiar with that plugin, but I know that you can do exactly this with Taxonomy Images. In fact, there's a recent (resolved) support request with exactly the same question.


1

register_taxonomy() is the tool for the job. From the Codex: This function adds or overwrites a taxonomy. One option would be to copy the register_taxonomy() $args and modify them. However, that would mean that any future changes to the original register_taxonomy() code would be overwritten. Therefore, at least in this case, it's preferable to get the ...


0

You want to use the register_taxonomy_for_object_type function documented here add_action('init','fix_my_tax'); function fix_my_tax(){ register_taxonomy_for_object_type('taxonomy', 'post_type'); }


0

Not sure why you would try this with taxonomy. I would suggest making a meta_key "country" with the values. Then you can query it like in the documentation: $user_query = new WP_User_Query( array( 'meta_key' => 'country', 'meta_value' => 'Israel' ) ); Not sure why your taxonomy-query doesnt work, looks fine also, i use it like this for my ...


0

Figured out the answer! It turns out that in ACF, if you're using radio buttons and have key set for each value, the keys CAN in fact contain spaces! By matching the keys to the values (case-insensitive) I was able to get the conferences to display on the single-team posts.


1

Thanks Vancoder for your help!!! I have been ripping my hair out all day trying to figure it out. Funny enough your solution was one of half a dozen I wrote on my whiteboard, BUT I had no clue how to actually create an array with that as a key. I am a noob like that. Below is the code I ended up using with some comments for anyone else trying to do this! ...


1

Rather than outputting your terms in that initial loop, I would use it instead to build a new array, with your issue_date as the key: $my_new_array = array( ); foreach ( $terms as $term ) { $issue_date = get_field( 'issue_date', $term ); $my_new_array[$issue_date] = $term->name; } You can then loop through this new array in order: ksort( ...


0

I believe I have come up with a temporary solution from random miscellaneous sources online. I would love for someone to expand on my answer to make it more "bullet proof" so to speak. However, in the short run, this solution does work. Hook into the current rewrite rules. add_action('rewrite_rules_array', array($this, 'rewrite_rules_array'), 100); ...


1

That is expected and how Template Hierarchy works. I know there was a track ticket raised a couple of years ago regarding this issue if to an index for archives should be introduced in core or not. (EDIT: Found the ticket, check it out here: Ticket #13816 There should be built-in index pages for taxonomies) That idea was scrapped and will never see light in ...


0

You can use the meta_box_cb parameter of the register_taxonomy function to define your own function for the meta_box. With the help of this article I have created this snippet: function YOUR_TAXONOMY_NAME_meta_box($post, $meta_box_properties){ $taxonomy = $meta_box_properties['args']['taxonomy']; $tax = get_taxonomy($taxonomy); $terms = ...


2

You can make use of the hide_empty argument of get_terms(), it defaults to true. Do it somewhat like this: $args = array( 'hide_emty' => false ); $terms = get_terms( 'wpsc_product_category', $args );


0

You have to make your rewrite rules account for the paged parameter, because otherwise they won't. It would look somewhat like shown below. function test_add_rewrite_rules() { add_rewrite_rule( 'businesses/(eat|stay|play)/(.+)/page/([0-9]+)/?$', ...


0

Essentially your issue is that you have extra data specific to the term and WP doesn't natively store such data. On top of my head the low hanging ways to make it would be: Maintain the list of schools/colors and whenever school term is assigned automatically assign respective colors by code. Create term metadata tables (which would work via regular ...


0

It seems the issue was in part down to their being a theme-init.php in the child theme which was overwritting parts of the theme-init.php in the parent / cherry framework theme. I resolved the issue by adding the following code into my child theme's theme-init.php; register_taxonomy('team_tag', 'team', array( 'hierarchical' => false, 'label' ...


0

The most probable cause of this issue is in the use of hypens (-) in your custom taxonomy name. Hyphens are extremely troublesome when used in custom taxonomy names, so by rule they should be avoided at all costs. If you need to separate names in a custom taxonomy name, or even a custom post type name, you should and only use underscores (_). Also avoid the ...


0

register_post_type( 'team', array( 'label' => theme_locals("our_team"), 'singular_label' => theme_locals("our_team"), '_builtin' => false, // 'exclude_from_search' => true, // Exclude from Search Results 'capability_type' => 'page', 'public' ...


0

I would do it in php in two parts rather than one big raw sql statement, for safety reasons, eg in your "functions.php" put: function wpse160706() { $old_post_type = 'films'; $new_post_type = 'post'; $category_slug = 'directors'; $taxonomy = 'category'; global $wpdb; $sql = $wpdb->prepare( 'SELECT p.ID FROM ' . $wpdb->posts . ...


1

I found a solution here: Custom post types, taxonomies, and permalinks TheDeadMedic's solution worked like a charm. function filter_post_type_link($link, $post) { if ($post->post_type != 'project') return $link; if ($cats = get_the_terms($post->ID, 'project_categories')) $link = str_replace('%project_categories%', array_pop($cats)->slug, ...


3

while agreeing 95% with Drew's answer I would like to attend to another point It's normally advised to not include custom types or taxonomies in themes as the themes will be less useful to other users, and would not be accepted by the WordPress theme repository. The word of the maintainers of the wordpress.org repository is not the word of god and ...


2

I don't think there's anything wrong with including functionality in a client theme. We do it with almost all of our custom builds as standard practice. What's really in play here is the difference, I think, between 'commercial' and 'client' work. The prevailing wisdom on not including custom post types/custom functionality in themes is more aimed at the ...


0

The answer is that there is no way to do what I'm asking, at least, there's no simple/easy way. Pieter Goosen writes in their comment above: Styling is theme territory, not plugins, and that is where your tables should be. The best possible solution is a shortcode if you need this to be in a plugin. I would add to this that custom templates are ...


2

To display the description from a taxonomy term, you can use echo term_description( $term_id, $taxonomy ); where $term_id is the term ID of the current term and $taxonomy is the taxonomy the term belongs to. For general use on your taxonomy page, you can just use echo term_description();


1

This not a complete and ready-made answer, but the below should get you started. First thing to note is, deleting and modifying are different functionalities, so different functions and hooks are relevant to it. Namely we are talking about wp_delete_term() - source and wp_update_term() - source - regarding the functions. So lets take a look at ...


0

I found that the best way to handle this problem was to leverage the post_class function and add the loop through the function.php file. this is the code in the function.php file: function term_class($classes){ global $post; $taxonomies = array('project_type'); $terms = get_the_terms( $post->ID , $taxonomies); foreach ($terms as $term) { ...


2

If you use return then your loop will not work properly. You can try the code this way: <?php while($portfolio->have_posts()) : $portfolio->the_post(); ?> <?php $term_class = ''; $categories = get_the_terms($post->ID, 'project_type'); foreach($categories as $category){ ...


0

I've managed to solve this using Javascript to 'open' the menu item when on the edit tags page in the plugin. Relevant plugin PHP file $screen = get_current_screen(); // Check we're only on the edit-tags page in the plugin if ('edit-tags' === $screen->base && 'subscriber' === $screen->post_type) { wp_enqueue_script( $this->plugin_slug ...


1

This is working. Pieter Gossen's method of counting is better, so I implemented that as well: function the_producers($post_id = false) { if ($post_id == false) { $post_id = get_the_ID(); } $producers = get_the_terms($post_id, 'producers'); $q = count($producers); if( 1 == $q ) { $str = reset($producers)->name; ...


0

You have some messed up code. I have reformatted your code to code which actually works. The following solution allows you to give your Custom Post Type menu a menu name of what ever you want. Just change the label "menu_name". POST TYPE // Create the news custom post type register_post_type('nwcm_news', array( 'labels' => array( ...


0

It's more readable and just generally more WordPress-y to use the built-in term_description() function! <?php echo term_description( {term_id}, '{taxonomy}' ); ?>


1

Instead of counting inside your foreach loop, why not count the result from get_the_terms. Something like this $q = count($producers); From that, you can then use a conditional like if( 1 == $q ) { // do something when only one term exists }else{ // do something for mutliple terms }


3

Really, you could probably refine this more and come up with better names, I just wanted to make it functional ^_^ ! First thing's first -> Let's include JQuery because I don't want to do this in vanilla JS. function lets_include_jquery() { wp_enqueue_script( 'jquery' ); } add_action( 'admin_enqueue_scripts', 'lets_include_jquery' ); Now let's throw ...


0

A custom field is a custom post meta data made by the user or a theme/plugin, in this case that custom field is named yesno. To add a column for it to posts or custom post types (myposttype): add_filter('manage_edit-myposttype_columns', 'my_custom_columns'); function my_custom_columns($columns) { $columns['yesno'] = 'Yes/No'; return $columns; } ...


0

Two things! 1) Don't use query_posts()! Instead, for situations like this, use the pre_get_posts action to modify the query. 2) I don't think you actually want to be using a loop here at all (so neither query_posts() nor pre_get_posts or even WP_Query). Rather, I think you're looking for wp_list_categories. In your template, you'd probably do something ...


1

The code you need will vary slightly depending on whether the Conference field is storing a text string (like "Big Ten") vs. the ID of the Conference post. I'll include both: Text String Example // place this code inside the loop of your single-team template $conference_name = get_post_meta( get_the_id(), 'conference', true ); $conference = ...


0

solved it so: $part_brand = get_terms('brands', 'hide_empty=0'); <label for="part_brand">Бренд</label> <select name='part_brand' id='part_brand'> <option value='' <?php **$brand_names = wp_get_object_terms($post->ID, 'brands');** if (!count($brand_names)) echo "selected"; ?>>None</option> ...


1

You use the hide_empty argument for $terms, but not for $this_term inside your loop. Also, with the way you're generating your select, it would be a lot more efficient to just query top-level terms for the main loop: $terms = get_terms( 'device', array( 'hide_empty' => false, 'parent' => 0 ) ); And then drop if($term->parent == 0) {... inside ...


0

I've found the problem. I'm using get_terms() twice, once for the parents and once for the children. It seems like I didn't add hide_empty=false to the one that gets the children.


0

Still sounds something went wrong with your rewrite rules, try adding flush_rewrite_rules() at the end of your function that contains the registrations calls you posted in your questions. Like this: flush_rewrite_rules( false ); Setting the parameter $hard to false means you won't update the .htaccess and just do a update of the rewrite_rules transient. ...


0

I've tested your code and it works perfectly if you register the post type in the init action hook. In your code I don't see the action hook where you register the post type. Cna you try this? (remember to flush rewirte rules after update the code. Note that I remove the undefined variable $labels in the $args array for taxonomies): add_action('init', ...


0

Figured it out for anyone who wants to know: function update_school( $post_id ) { $post_author_id = get_post_field( 'post_author', $post_id ); // get the post author ID $school_name = get_the_author_meta( 'school2', $post_author_id ); // from the post author ID, get the author meta $term = term_exists( $school_name, 'school'); wp_set_post_terms( ...


0

If I understand you correctly, you need to show all posts from a term when a term's page is being displayed. Before I answer the real question, there are a few points I would like to highlight since you are new to Wordpress Never use hyphens (-) to separate names in custom post type names and custom taxonomy names. They are extremely troublesome later, ...


2

You cannot use the same object of WP_Query twice. Therefore you need to create another one with a tax_query parameter to fetch posts which are not assigned to any term. //fetch all reviews which have no assigned term in 'review-product' $taxonomy = 'review-product'; $post_type = 'reviews'; $args = array( 'post_type' => $post_type, 'tax_query' ...


2

Try this: function custom_set_term_to_post(){ $args = array( 'post_type' => 'post', ); $all_posts = get_posts(); foreach ($all_posts as $key => $post) { $tag_name = 'post_tag'; // required tag name $term_list = wp_get_post_terms($post->ID, $tag_name, array("fields" => "ids")); if ...


0

I have found a solution. Thanks to @Tarukus as his answer was helpful. Again, my goal was to display terms (not posts) from my custom taxonomy via an on/off switch. To do this, I used Advanced Custom Fields and created a "Select" field with two values (on/off). Once this field was applied to my taxonomy I could select a value for each term. The default value ...



Top 50 recent answers are included