Tag Info

New answers tagged

0

You don't have to set that code in your functions.php. Naming a file single-press.php should do the trick if you named well you custom post type when you declared it. The post type should continue to use single.php. I this doesn't work, please provide wp version and custom post type declaration.


0

There are two ways to do this: You can try outputting the category name using the array index and wrap it around a custom class. echo "<div class="category-custom-class">" .$category[1]->cat_name. "</div>"; Or You can make use of :nth-child in CSS. Suppose the category list is generated inside the class category. Then I would use: ...


1

Use this one- 'category__not_in' => array( 93, 94, 95 ), instead of- 'category_not_in' => 93, Note: The term is category__not_in, not category_not_in. Use 2 underscores after category. Edit: You are using- 'offset' => 1 That forces to show posts from 2nd one (skips the first post). So, it's showing one post less! If you use 'offset' => ...


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

Your best bet will be a bunch of apache rewrite rules. Place something like this above the # BEGIN WordPress line in your .htaccess file: <IfModule mod_rewrite.c> RewriteRule ^subdirectory/(.*)$ /anotherdirectory/$1 [R=301,NC,L] </IfModule> So, using your example of redirecting /review to /reviews: <IfModule mod_rewrite.c> ...


0

This is not an optimal answer, but it works well enough for the client to have a page that does what they want. Since I cannot seem to find a function that will do the nested loops as described above, I used a series of query objects, one for each year the client would like to list. '$PastConferences2015 = new WP_Query('category_name=2015'); 'while ( ...


1

From what I can tell, this stems from your use of get_post_field(), which is reserved for fields found in the posts table of the database (ie: built-in to WordPress, rather than custom fields). For custom fields you should use get_post_meta().


2

I'm a bit unsure of you are actually asking, so apologies if I understood it wrong. You can use get_category() to get the category object and then just simply echo the $count property value $cat_count = get_category( 'ID OR ROW OBJECT' ); echo $cat_count->count;


2

As I already stated, straight from the codex exclude (string) Excludes one or more categories from the list generated by wp_list_categories. This parameter takes a comma-separated list of categories by unique ID, in ascending order As you have stated, you have to use the category slug. To make this possible and dynamic, I think the best will be to ...


0

Here is an updated version of answer provided by @toscho, tested and working with WP 4.1.1. class FGW_Cat_Slug_Walker extends Walker_CategoryDropdown{ public function start_el(&$output, $category, $depth = 0, $args = array(), $id = 0){ $pad = str_repeat('&nbsp;', $depth * 3); // Create the padding (before nested terms) /** ...


-1

There's a small error on your first line of code. You should separate 'each' category with quotes in the array. So the first line should be: <?php $categories = get_categories(array('exclude' => 'apps', 'windows')); ?>


2

As documented in the codex you could use the following $query = new WP_Query( array( 'category__and' => array( 2, 6 ) ) ); //post has to be in category with ID 2 AND 6


-1

You can use the WP_QUERY class to search for the posts in some specific categories, here is an example: $query = new WP_Query( 'cat=2,6,17,38' ); Here is a link to the documentation where they explain how to use the results to build a loop and display the posts in the results.


0

The Codex says: Note: The category parameter needs to be the ID of the category, and not the category name. Note: The category parameter can be a comma separated list of categories, as the get_posts() function passes the 'category' parameter directly into WP_Query as 'cat'. So it'd be same as WP_Query()'s Category parameter - cat.


0

Try this, $show_count = 0; // 1 for yes, 0 for no $hierarchical = 1; // 1 for yes, 0 for no $taxonomy = 'productcategory'; $title = ''; $args = array( 'orderby' => $orderby, 'show_count' => $show_count, 'hierarchical' => $hierarchical, 'taxonomy' => $taxonomy, 'title_li' => $title ); <ul> <?php ...


1

I think this is more a general question than a specific one and I'll be treating it as such. Taxonomies in general are used to group posts together that shares the same characteristic. The post_tag and category taxonomies are the most widely and commonly used of the four build in taxonomies to achieve this. Also very popular are custom taxonomies which ...


2

// Getting Parent ID $parent = get_term_by( 'name', 'Session 2015', 'category'); // Checking if SubCategory Exist. $term = term_exists('Photos', 'category', $parent->term_id); //if Exist Do the query if ($term !== 0 && $term !== null) { $query = new WP_Query( 'cat='.$term['term_id'] ); } References: term_exists get_term_by


0

The problem was the else condition. I removed it and the code works fine.


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

You can use wp_list_pages with the child_of argument: /** * Display hierarchical list of all posts for a given post. * * @param int|WP_Post $post Display for post. Defaults to current post/page. */ function wpse_184554_list_section( $post = null ) { if ( ! $post = get_post( $post ) ) return; if ( $post->post_parent && ...


0

As a first condition: Have you tried, if you retrieve sub categories at all? $sub_categories = get_terms( 'product_cat', $args2 ); echo '<pre>';print_r( $sub_categories ); If you have sub categories, you would still have a problem with your foreach: foreach ($sub_categories as $subcat) { $sub_categories = ...


4

You can use the category__in argument: // use get_the_category( $post_id ) if you are outside the loop $categories = get_the_category(); if( $categories ){ $related_posts = get_posts( array( 'category__in' => $categories ) ); }


0

Have you checked the WPMU Site Wide Categories page? It has a warning that it may be outdated, but it may be a good start. You also have the plugin Multisite Global Terms. Check the code and see if you can make it work or get ideas for your particular case.


1

I just made it for a client, you'll have to do it on the pre_get_posts action. That means you will add parameters to the Wordpress query before it returns the posts. Add this to functions.php: // advanced search functionality function advanced_search_query($query) { if($query->is_search()) { // category terms search. if ...


0

If you want to display post in three columns by category then you can choose my best answer this question, but it’s hard because I can’t give a “one solution fits all” answer. The code I provide here will have to be changed and adapted for your own theme. Everyone’s theme is slightly different, so all I can really do is give a generic response and hope that ...


0

We can change the default behaviour of including posts attached to child categories by mapping the category_name query var (set from pretty permalinks) to category__in (which ignores child categories): function wpse_184127_ignore_category_children( $wp_query ) { if ( $wp_query->is_main_query() && $wp_query->is_category() && $name = ...


1

As already stated, you should never use query_posts as it breaks the main query and many functionalities that other code and plugins rely on Note: This function isn't meant to be used by plugins or themes. As explained later, there are better, more performant options to alter the main query. query_posts() is overly simplistic and problematic way to ...


1

Don't use query_posts() ;). In short query_posts() over-rides the global $wp_query. So subsequent calls replace previous ones. Instead you should use pre_get_posts: function wpse183914_filter_child_cats_and_order( $query ) { //Alter front-end main query for categories only. if ( $query->is_main_query() && $query->is_category() ...


0

In short, yes! $args = array( 'post_type' => 'summerartcamp', 'cat' => 15, //This is for the Morning Group - I'll have a second loop for the Afternoon Group 'order' => 'ASC', 'meta_key' => '_expiration-date', 'orderby' => 'meta_value' ); $the_query = new WP_Query( $args ); if ( $the_query->have_posts() /* Make sure ...


2

If you look at wp_get_archives() you will notice that the link is generated by get_archives_link(). That function supplies a filter that will allow you to replace the parens. This is fairly crude but does work. function archive_link_wpse_183665($link) { $pat = '|\(([^)])\)</li>|'; // preg_match($pat,$link,$matches); // var_dump($matches); ...


2

This same exact question was asked earlier this week or over the weekend, and it had me thinking. Here is the idea that I came up with. If you look at the source code of the WP_Query class, you will see that sticky posts is only added to the first page of the home page. There is also no filter supplied to change this behavior in order to set the required ...


1

To expand on @pieter-goosen's comment, you do indeed want to use pre_get_posts. In your example, by using WP_Query, you're overwriting the entire query and just resetting most parts of it to default. In fact, you're probably not seeing a specific category of posts at all. You should be seeing all posts since that's the default of the WP_Query class. So ...


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

I think these should be separate taxonomies. Category is actually a taxonomy in its own right. You would create a taxonomy for each of the filters/drop-downs. This may seem like overkill but i think it will make it easier to work on additional features down the road. Add the following method to your functions.php. Replace 'rwc' with your theme's domain: ...


1

Is the file named content-expertises.php or category-expertises.php? WP will use the first template file it finds in your theme directory from the following list: category-slug.php category-ID.php category.php archive.php index.php https://codex.wordpress.org/Category_Templates


0

I have install "Advance Permalink" plungin by John Godley, on 31st March' 2015 for redirect me previous permalink structure of http://punch2crunch.com After 36 hours my all cotegories start creating automatically 404 errors and one category working but sick to single post. If this same is happening with you then you have to paste a thing only. Follow the ...


0

Another way that @toscho's solution made me try, and worked for me, is this scheme: http://example.com/videos/?tag=crazy


0

Finally i used the following code and i add category from my plug in. class MyPluginClass { public function __construct() { add_action( 'init', array( $this, 'sample_insert_category') ); } public function sample_insert_category() { if(!term_exists('Test','product_cat')) { wp_insert_term( 'Test', ...


1

In your functions.php file, use pre_get_posts and swap out the -1 in the following code with the category I.D you want to exclude from your posts page. function exclude_category( $query ) { if ( $query->is_home() && $query->is_main_query() ) { $query->set( 'cat', '-1' ); } } add_action( 'pre_get_posts', 'exclude_category' ); ...


0

Use the parameters cat or category__not_in: $query = new WP_Query( 'cat=-1234' ); The minus means to exclude, the ID is used. $query = new WP_Query( array( 'category__not_in' => array( 1234 ) ) ); Uses the ID too. Use get_cat_ID() to get the ID by name or get_category_by_slug() to do it by slug, the latter returns an object though.


1

The syntax for adding an action in WordPress WITHIN a class is somewhat different. Your code will have to look somewhat more like the following... class MyPluginClass { public function __construct() { add_action( 'init', array( $this, 'sample_insert_category') ); } public function sample_insert_category() { ...


1

Does the folder 'biljke' exist on the server by any chance?? i.e. do you have wp-admin, wp-content, wp-includes AND biljke as folders in your Wordpress root? [Reposted as an answer so it can be accepted, probably should have done that in the first place without trying to comment!]


0

Figured out a solution. Ended up querying each categories using "foreach" and inserting my custom function into the loop. Not sure if it's the best approach but I got it to work so eh. No one else seems to want to help.


1

To display a list of categories on your page by just putting something into the content area, you need a shortcode. You can create a shortcode by using add_shortcode. This defines the tag and the function to call when that shortcode is used. Here's a basic example that creates a shortcode [my_cat_list]: /** * This creates the [my_cat_list] shortcode and ...


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


1

The is_home() conditional tag applies to the posts page according to your reading settings or home.php file as opposed to the is_front_page() conditional which applies to the page on front according to your reading settings or your front-page.php file, if it exists. Try changing is_home() to is_front_page() As for another possible problem might be, take a ...



Top 50 recent answers are included