Tag Info

New answers tagged

0

I found a hacky solution involving redirecting the user: if ((basename($_SERVER['SCRIPT_NAME']) == 'edit.php')) { // your code here $author = wp_get_current_user(); if(isset($author->roles[0])){ $current_role = $author->roles[0]; }else{ $current_role = 'no_role'; } if($current_role == 'ai1ec_event_assistant' && ...


0

So this hasn't been 100% tested yet, but the basic logic is there. The IF checks for the presence of the catID and if it isn't there; update user meta with current list + category ID. Need to do some more work on removing from the list but it's the same principal. Check string for category ID. If exists, remove from string and store as new string. Update ...


1

Set the display argument of the function to false. <h2> <?php if (is_category()){ echo 'Category: ' . single_cat_title( '', false); } ?> </h2> Or, to use the function in its more "helpful" form you could do: single_cat_title('Category: '); If the display argument is true, WordPress automatically ...


0

Custom post type archives don't have year/month rewrite rules, they only have a single archive which will be at /press/ and /more_posts/. If you want those, you'll have to add them yourself. For the taxonomy, add the taxonomies argument to your post type registration to insure the two objects are connected, see the note about this on register_post_type.


1

Remove query_posts and add a pre_get_posts action to your functions.php file to modify sort order: function wpd_category_sort_order( $query ) { if ( !is_admin() && $query->is_category() && $query->is_main_query() ) { $query->set( 'order', 'ASC' ); } } add_action( 'pre_get_posts', 'wpd_category_sort_order' );


2

I would recommend using the category_template filter - just check if the current category is an ancestor of 67: function wpse_179617_category_template( $template ) { if ( cat_is_ancestor_of( 67, get_queried_object_id() /* The current category ID */ ) ) $template = locate_template( 'category-slider.php' ); return $template; } add_filter( ...


0

You should delete this part (as Pieter wrote): $the_query = array( 'paged' => $paged, 'cat' => $cat, 'posts_per_page' => 20, ); $arrgs = new WP_Query( $the_query ); $temp_query = $wp_query; $wp_query = NULL; $wp_query = $arrgs; I'm supposing that you want to show 20 posts per page, you could either configure that in ...


0

If you're in the single custom post template, you can get the terms that the post belongs to by use of $terms = get_the_terms( get_the_ID(), 'btp_work_category' ); Then you need to determine parent term and display it with its children. The code below assumes that the post belongs to one top category (term) and the taxonomy tree has no more than 2 ...


0

/product-category/her+shoes/ This is it you can just append the categorie you also want to show with a + sign Thanks to jpussacq for pointing to the write direction Filter posts under multiple categories?


0

If you want to create sub sub category in wordpress then you choose this method:- 1-Use the parent category as the widget title 2-Show post counts in bracket next to the name 3-Hide empty sub-categories 4-Add a link to the parent category to the widget title 5-Show the full sub-category tree so it include sub-sub categories and so on as well 6-Display the ...


1

For anyone else having this issue - the working code looks like this (placed in the functions.php file): function default_post_type($post_id) { if (in_category('YouTube')) { set_post_format($post_id, 'video'); } } add_action( 'publish_post', 'default_post_type' ); Happy WordPressing


0

I'm also wanting the post to be assigned the post type "Video". You can't just change a post to a different Post Type. There is a difference between "Post Type" and "Post Format". From your examples I assume you would like to change the "Post Format", as per the codex http://codex.wordpress.org/Function_Reference/set_post_format, you would need to ...


0

I found the setting in WP -> Theme Panel -> Categories


1

This is not just happening in Wordpress 4.1.1, but for all version that I know of from version 3.0 when I started on Wordpress Posts and taxonomy terms are stored in different tables in the db, posts in wp_posts and taxonomy terms in wp_term_taxonomy. To create a relationship between terms and posts, there is another table called wp_term_relationships. This ...


0

It might be not your case but if behind the scene permalink settings have been switched from default one, then the request: ?category_name=slug1+slug2 is rewritten to /category/slug1/ or /category/slug2/ so only the posts from one category are shown.


0

You should check out the options from this theme. Probably you can set all this in the theme options. Accordion to the demo pages from The7 theme page you can choose for a list layout i.o a grid layout http://the7.dream-demo.com/blog/blog-list/5-blog-list/


0

You could use get_ancestors(). You can transform this: <a href="#" class="<?php $category = get_category($cat); echo $category->category_nicename;?>"><?php single_cat_title('') ?></a> Into this (I don't know what $cat is as you have not shown it in your question, I assume it is a category ID, if not, you have to provide ...


0

You can modify the arguments that the search query uses so it will return empty terms. This is a quick hack job, perhaps someone can improve this. I put it together by looking at the browser console when performing a search. There you can see the parameters it's sending to admin-ajax.php to perform the search. In the case of searching for a term in the ...


0

In WordPress 4.1.1 at least, In the Menu editor, Categories > View All Tab shows empty categories.


0

I've used the code linked to below for just such a requirement. https://gist.github.com/seedprod/1367237 Doing this, you don't create a new image size every time you upload a file via the Media Editor, but only when necessary. So essentially, you just go in and add the call to resize the image "on the fly" in your templates where needed. So you'd add that ...


0

Ended up doing this, which seems much more simple: if (is_category()) { $this_category = get_category($cat); if (get_category_children($this_category->cat_ID) != "") { // This is the Template for Category level 1 include(TEMPLATEPATH.'/location.php'); } else{ // This is the Template for Category level 2 ...


1

You could use the template_redirect hook to check and see if your post is a category and then whether it is a sub-category ... and if so, force a different template. For example (assuming you are using wordpress categories) function my_maybe_override_category_template( $template ) { # Make sure you are about to show a category term if ( ...


2

Use the terms_clauses filter, which passes all the various components of the query (fields, join, where, orderby, order & limits), and implement your own "search" argument: function wpse_178511_get_terms_fields( $clauses, $taxonomies, $args ) { if ( ! empty( $args['surname'] ) ) { global $wpdb; $surname_like = $wpdb->esc_like( ...


0

For the example you posted, the article is styled according to the css rule(s) for category-selling-and-advertising which is defined last (among the category-* classes) in the article's class attribute. You need to intercept the functionality of post_class() to change the order these classes appear. The post_class filter will do the job for you: ...


0

One way to do this would be to create a custom widget which displays categories using wp_list_categories(). Then exclude any categories you don't want displayed using the exclude option of wp_list_categories(): http://codex.wordpress.org/Template_Tags/wp_list_categories#Include_or_Exclude_Categories. This example below creates a custom categories widget in ...


1

According to the Wordpress Codex page on Template Hierarchy, you create a template file with the name of taxonomy-portfolio_category.php. WordPress will use that to display the archive for that taxonomy. You can also use taxonomy-portfolio_category-{term_name}.php to create templates for specific terms in your taxonomy.


0

I think it could be a good idea to create two more hierarchical (category like) taxonomies, called Artists and Albums. This way, you'll be able to query your posts based on taxonomy / term relationships. Basically, what I'm saying is this: Artists -> custom hierarchical taxonomy List item -> custom hierarchical taxonomy Songs -> custom post type Genres -> ...


2

The permastruct /%category%/%postname%/ will include the categories and subcategories in the URL from top to first assigned child. So, if you want the URL be site.com/source/books/moby-dick/*postname*, you have to assign the post only to "Moby Dick". Assigning the post only to "Moby Dick" category will still show the post under "source" and "books" category ...


2

Pro tip - don't custom query unless you need to (you don't). And never use the guid field. if ( is_singular() && $cats = get_the_category() ) $cat_id = $cats[0]->term_id; // Category ID for current post elseif ( is_category() ) $cat_id = get_queried_object_id(); // Category ID for current archive else $cat_id = 0; // No cats $posts = ...


0

I think i have a function that will do it for you. The usual WP way to highlight the menu item is to add the class "current-menu-item" to the item, then you can style highlighted links with CSS. In this case you want to highlight a taxonomy menu link if we're in a post for that taxonomy, is that right? For example if we're in a post in "CategoryX" we want ...


-1

Try This : <!-- Category Archive Start --> <ul class="catArchive"> <?php $catQuery = $wpdb->get_results("SELECT * FROM $wpdb->terms AS wterms INNER JOIN $wpdb->term_taxonomy AS wtaxonomy ON ( wterms.term_id = wtaxonomy.term_id ) WHERE wtaxonomy.taxonomy = 'category' AND wtaxonomy.parent = 0 AND wtaxonomy.count > 0"); ...


1

I was able to get the result that I wanted by putting the following into the functions.php file in my theme directory: function exclude_category( $query ) { if ( $query->is_home() && $query->is_main_query() ) { $query->set( 'cat', '-208' ); } } add_action( 'pre_get_posts', 'exclude_category' ); The result of using this ...


1

posts_per_page=-1 is perfectly fine. This is used to get all posts. As for your code, you should never ever use query_posts unless you want to intensionally break stuff on your pages. This is one of the most common functions used and yet the one function that causes the most problems in a website. I have recently done a post on custom queries and have ...


0

What do you try to achieve exactly ? Do you want to list categories that have an image custom field ? If yes, try this : <?php $args = array( 'orderby' => 'name', 'order' => 'ASC' ); $categories = get_categories($args); foreach($categories as $category) { // check if image field is set on category if ...


0

Thanks the the replies. I solved my problem with jQuery. Here is the code: jQuery(document).ready(function ($) { $("#category-tabs li.hide-if-no-js").hide(); //Hides Most Used tab $("#category-all input:checkbox").change(function () { var max = 2; // Max allowed cats var count = $("#category-all input:checked").length; //counts selected cats ...


1

I assume you want the field for the current category archive, not the category of the post inside the loop? Try get_queried_object_id() instead of the_category_ID( $echo ). In single.php, you just need a slightly different iteration of your original attempt: if ( $terms = get_the_category() ) the_field( 'bgcolor', 'category_' . $terms[0]->term_id ); ...


0

The problem is in second side of condition ... && ( has_category( ) || has_tag() ) { ... try change with ... && has_term( null , 'collections' , $post -> ID ) ){ ... where "collections" is slug name for registered custom terms ( custom tags and categories ) also I want recommend you to use other slug name for custom tags and ...


1

You could use tax_query to solve this problem. I assume 4 and 6 are only categories, so you'll probably need to construct the queries within the $tax_query array rather than declare it, but let us know if that is a problem. Just remember that relation => 'AND' must be inclded. $tax_query = array( relation = 'AND', array( 'taxonomy' ...


1

My suggestion would be to pass different arguments to Wp_Query Class. using 'cat' property, passing category Ids. <?php $custom_query = new WP_Query( array( 'cat' => '1,2,3,4' 'post_type' => 'my_post_type', 'posts_per_page' => -1, 'orderby' => 'title', 'order' => ...


0

You really should try to avoid using query_posts if at all possible. See When to Use WP Query vs Query Posts vs Get Posts Here is a pass through a loop using WP_Query: $args = array( 'tax_query' => array( array( 'taxonomy' => 'region', 'field' => 'id', 'terms' => $region_id ) ) ); ...



Top 50 recent answers are included