Tag Info

New answers tagged

0

$seach_values can be changed whenever the site redirect, be sure that $search_values still keeps the input values from your search form. To be sure I suggest use GET or POST to pass the values from form. So, your comparing statement should be $_GET['grades'] == $term->slug Here I suppose your search form use method="GET"


0

The link you added in your question is for Displaying the other post that share the same TERM. And I guess you want to display the all post for the current taxonomy not the single term ? Then just used the default $wp_query to do it just remove the custom wp_query and keep the loop same.


1

This can be easily done with your own custom function. What you want to do here is, get your object from get_terms() which will hold your term objects, check if your unique key is set as a parameter and then according to that, remove that key/pair and add it to the back Now, lets put that into code: (I have commented the code to make it easy to follow) ...


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' => ...


0

An idea that came to me is to add a term in your taxonomy called something like 'append' and then make the terms you want to be appended at the end of your terms list children of that term. Then it is only a matter of doing the appropriate term queries, ie get all terms with append as it's parent and then exclude them when quering for the rest. This way you ...


0

I stumbled across similar issue lately. If you are comfortable with using a plugin, you can install Custom Taxonomy Sort. Even though it was not updated for over two years, it solved the problem for me. Basically, it allows you to sort terms manually from the dashboard.


0

There may be a better way of doing this, but you could probably just do two queries. Maybe something along these lines (untested): $loner_term = X; //put whatever the id of the term you want at end $taxonomies = 'YOUR_TAXONOMY_NAME'; ) // get all of the alphabetical terms and exclude the one you need at the end $alpha_args = array( 'orderby' => ...


0

Yeah I found the answer an another website. Taxonomies have a restriction that they cannot have uppercase characters in their name they can only have lowercase and underscore characters. that`s the problem.


1

As you have already pointed out in your question, custom taxonomies are the way to go here. For this taxonomy to behave like the build in taxonomy post_tag, you need to set the hierarchical parameter to false. To make these taxonomy available to only your two specific post types, you need to specifiy this when registering your taxonomy. Example ...


1

If you are just after the term name in your code, you can add array( 'fields' => 'names' ) Or for PHP 5.4+ ['fields' => 'names'] as the third parameter to wp_get_post_terms. This will just retrieve the names of the terms attached to the post. You can then get and display the first post term name with echo $terms[0]]; As @birgire already ...


2

What about using: echo get_the_term_list( $post->ID, 'artist-genre', '<li>', ',</li><li>', '</li>' ); instead, to generate the HTML list? Or simply: the_terms( $post->ID, 'artist-genre', '<li>', ',</li><li>', '</li>' ); that's a wrapper for get_the_term_list(). Also notice that you're missing the ...


1

get_the_term_list() returns HTML but you are trying to use it as if it returned a term ID -- 'blog_cats' => $blogcats,. That is not going to work. You will need to use get_the_terms() and a tax_query (I think. I am not 100% sure). Something like: $blogcats = get_the_terms($post->ID,'category'); // var_dump($blogcats); $blogcats = ...


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

Add the value you want before the "meaningful" url variables (city, area, etc) to the slug like this: "uk/([^/]*)/([^/]*)/?$" => 'index.php?city=$matches[1]&area=$matches[2]&something=$matches[3]', This way it will only "capture" those URL variables (city, area) if "uk" is at the beginning. A more complete example might look like this //Set ...


1

Thanks to Rarst for the tip. Here is the code I came up with to accomplish redirects for two similar taxonomy/post type set ups. This basically does what I indicated in the OP. If I hit a single post with a top-level term assigned to it, the url will go from domain/series/post/ to domain/series/ It simply strips the post's slug from the end of the url. ...


0

There is a template_redirect hooks which is perfectly suitable for task like this. Hook into template_redirect Check your context (is_single(), etc) Redirect with wp_safe_redirect() (if it's inside a site) die() to prevent execution from proceeding


1

Create a new template named e.g. taxonomy-course_topic.php In my example course_topic is the name of the custom taxonomy you registered. First parameter of register_taxonomy() function. See: register_taxonomy Taxonomy template


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 ...


4

The issue, I believe, is that if ($stories) is always returning true, een if there are no posts. It's then looping through the WP-Query elements, not the actual posts. Try this instead: if ( $stories->have_posts() ) { while ( $stories->have_posts() ) : $stories->the_post(); echo get_the_title( get_the_ID() ); endwhile; ...


0

Use a slash as value for slug... 100% working 'rewrite' => array( 'slug' => '/', 'with_front' => FALSE ),


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.


1

The number of posts attached can be found here: $term->count. So you could do the following: $class_empty_term = ''; if( $term->count == 0 ) $class_empty_term = 'empty'; $term_list .= '<div class="' . $class_empty_term . ' grid__item ...">'; $term_list .= '<div class="panel text--center">';


0

i got error in Your Code you insert taxonomy before register taxonomy after_setup_theme Load Before init So not insert taxonomy Please change after_setup_theme To init More Detail


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 ...


0

WP_Query is your answer for the first question, you will need to create a custom search form, and parse that data, in order to create your custom WP_Query. Here is a link with a tutorial to get you in the right direction. For the PDF part, I beleive it will be easier to tell the users to use Chrome and use the Print to PDF function, and create an stylesheet ...


0

I recently ran into a similar situation. While I can't currently remember the source, the code below will create a new entry into your taxonomy of choice, it could serve as the base for your needs. //Automatically creates a category in the case log and adds it to the post. function add_title_as_category( $postid ) { if ( defined('DOING_AUTOSAVE') ...


0

Ok, that is complicated :-) Have you considered using rewrite endpoints? I would not try and cram everything into the url unless you have a specific need or a requirement for that. domain/<series>/<episode-name> would be going directly to the episode CPT domain/cartoon-series/<series> - would go the the series CPT Then using rewrite ...


1

pagename is for request page (core page post type) by slug. What you want, if I understood correctly, is to get "attorney" posts that belongs to same case-log terms that current "case" post. I would do it something like this (not sure where you are going to execute the code, I've tried to code as universally as possible): if( is_singular( "case" ) ) { ...


0

I have managed to get this working using a rewrite, adding a query_var and doing some condiditional checking in my template file. I will post the code below that I used but although this works and seems to be working very well, It does not feel like the best way of doing it. If someone know of a better way of doing this please post the answer. I used this ...


0

Great question and solid answers. I really liked the approach by @jessica using the terms_clauses filter, because it extends the get_terms function in a very reasonable way. My code is a continuation of her idea, with some sql from @braydon to reduce duplicates. It also allows for an array of post_types: /** * my_terms_clauses * * filter the terms ...


0

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


0

Natively every post in WordPress has one specific permalink (if any and not counting non–pretty arguments–based shortlinks). This makes sense not just to WordPress, but also to other entities like people and search engines. It is certainly possible to make additional URLs to load posts in WP too. However it won't help you any with that. You would have to: ...


1

So you have 3 problems Problem 1, custom taxonomy post type Your first problem is a misunderstanding of what taxonomies and post types are. There is no such thing as a custom taxonomy post type. Taxonomies and post types are 2 different things. Post types are posts/pieces of content of a certain type. E.g. post, page, attachment, etc Taxonomies are ways ...


0

It might be a bit late already but I think the Woocommerce - Products By Custom Tax plugin should do what are you trying to achieve, I am the developer. For your case the shortcode of the plugin would be like this: [woo_products_custom_tax tax_name="city" tax_tags="nashik" columns="4"] If you want to show more cities you can place them separated by a ...


1

You second approach (EDIT 2) is quite buggy and inefficient unfortunately. Also, you are not going to do this in one query. As I already stated, you need to look at the approach in this answer I have recently done. You were almost there in your first edit, the only problem is, you cannot do this in one query, you will have to do two, one to get the ...


0

Your syntax is slightly off - $episodes is an instance of WP_Query, not an array. If you want a full-blown loop for using all template tags, use: while ( $episodes->have_posts() ) { $episodes->the_post(); the_title(); // Episode title the_content(); // Episode content } wp_reset_postdata(); // Restore current episode Otherwise you can ...


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) ); }


1

Add new file called taxonomy- mytaxonomies.php and put you code . But so far I know to add like in page..it is not available in wp yet


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: ...


0

I would do as @cfx suggested: register_taxonomy( // Call before register_post_type() to give rewrite rule priority. 'bike_category', // Should be singular, not bikes_category 'bike', array( 'rewrite' => array( 'with_front' => false, // This will strip the "blog" prefix 'slug' => 'bikes', ), ...


0

There are many options, but these functions are your friends: wp_insert_post - pass it some arguments and it will create a post and if succesful, return the post ID wp_set_object_terms - pass it a post ID, a custom taxonomy, and the terms you'd like to set fopen - for opening a csv file fgetcsv - reads in a single line from a csv and returns it for ...


0

You should really re-title this question and refine your question further. From what I gather you are actually trying to find out how to add posts to your custom post type that has custom fields via a CSV. My suggestion is to look for a plugin that imports posts from a CSV and either find one that already has a column for post_type and columns for custom ...


0

The rewrite rules are wrong. For example, you want to rewrite from community/tag/easter to 'index.php?pagename=community&stencil-tag=easter', so the regex should contain community/tag/ and not only tag/. Also, \d match only digits but the tag value is a string. Same apply to the rewrite for stencil-tag. You could use . to match any character, both ...


0

You could try this in your functions.php <?php add_filter('rewrite_slugs', function($translated_slugs) { // the possible translations for your slug 'product' $translated_slugs = array( 'product' => array( 'pt' => array( 'has_archive' => true,'rewrite' => array('slug' => 'produto'), ), ...


3

Here's a straight up simple solution. Requires you to have the most recent version of WordPress though. (or at least 4.1) Using nested taxonomy query. Taking what you have, and just adding to it a bit. $args = array( 'post-type' => 'episode', 'post-status' => 'publish', 'posts_per_page' => 4, 'tax_query' => array( ...


0

Did you try adding a count callback? // Register Custom Taxonomy function custom_taxonomy() { $labels = array( 'name' => _x( 'Taxonomies', 'Taxonomy General Name', 'text_domain' ), 'singular_name' => _x( 'Taxonomy', 'Taxonomy Singular Name', 'text_domain' ), 'menu_name' ...


1

I went through the two urls I added as comments, WordPress Codex documentation such as on register_taxonomy here some more and came up with this code that does seem to do the trick. Main addition is the added filter post_type_link to filter the cpt slug and load the term needed. // Register Custom Taxonomy function portfolio_taxonomy() { ...


1

This might solve your issue, and frankly, rewrites are still a little mistery to me, so I would not be able to help you out there, but there are two major issues in your code which you should first sort out before you try to sort out your rewrites Custom post type names (and for that matter, function names and custom taxonomy names) should be all small ...



Top 50 recent answers are included