Tag Info

New answers tagged

0

We can get the categories via get_categories() function (which will get the same categories as wp_dropdown_categories() function), but as array and without the markup. As the value is returned as array, we can loop through the categories and generate the HTML ourself. Usually, we would aim for a structure like this: <select name="categories"> ...


0

This seems to solve the issue: add_filter('pre_get_posts', 'query_post_type'); function query_post_type( $query ) { if( is_category() && $query->is_main_query() && empty( $query->query_vars['suppress_filters'] ) ) { $query->set( 'post_type', array( 'post', 'nav_menu_item', 'event')); return $query; } }


0

Well, what is the expected behavior? You use wp_set_object_terms and pass just a single term. If you want to make sure the specified term is assigned to the post, while being able to add as many other terms as you like, try it like this: function add_bookcategory_automatically( $post_id ) { if ( ! wp_is_post_revision( $post_id ) ) { $bookcat = ...


0

That is totally normal behaviour. If you want to remove category base you will need to write some custom rewrite rules, not simple rules I must say. From my point of view, removing category base requires a extra job in each request that is worthless because it doesn't provide any advantage for SEO or for better site navigation. Some popular plugins, like ...


0

In my opinion, you didn't exactly specify what includes restrict posting in specific categories. So here's a solution for the following: user can only edit posts that have the specific category user can not assign categories if user saves a post, the specific category will be assigned automatically :: Add the Filter and Action add_action( 'wp_loaded', ...


0

Create template file called not_allowed_user.php then add below code in function.php add_filter('template_include', 'restrict_by_category'); function check_user() { $user = wp_get_current_user(); if ( ! $user->ID || in_array('subscriber', $user->roles) ) { // user is not logged or is a subscriber return false; } return true; } ...


1

You have one or two problems here is_category() should be object of $query in your example code get_query_var('post_type') will always return false on a category page AFAIK, so that code is totally unnecessary Just a tip, when using pre_get_posts with any type of archive, also check for non admin pages as your back end will also be affected by this change ...


0

For creating taxonomy like category & tags for custom post type use register_taxonomy wordpress function Refer this wordpress codex for register_taxonomy


0

On default is each site in the network a single site in the context, menu, settings, widgets. But you can sync about custom source or plugins, like http://wordpress.org/extend/plugins/wp-multisite-mirror/ http://wordpress.org/extend/plugins/yd-wpmu-sitewide-options/ Also you can use the Multilingual Press plugin. This have a API fit synchronization about ...


0

you should try that with a custom Nav Walker. Here is a code example how it should work. I check if the menu item is a category link. If yes, there is another check -> category count.If the category don't have any posts the link won't be passed to the html output. class Menu_Category_Count extends Walker_Nav_Menu { var $number = 1; function ...


0

You could try $slidercategories_array = array(3,5,6,9,10,11,12,23,24,27); $in = implode( ',', array_map( 'absint', $slidercategories_array ) ); global $wpdb; $sql = $wpdb->prepare( 'SELECT tt.term_id, MAX(p.post_date) AS max_date FROM ' . $wpdb->term_taxonomy . ' AS tt ' . ' JOIN ' . $wpdb->term_relationships . ' AS tr ON ...


1

I think it would be useful to create a custom walker for your menu. In the following code example I made use of the Menu Item Object. You can take a look at the object output here. An object type is specified for every menu item. So I just compare if the object is a category. If yes I made use of the specified object ID to get the category + category ...


0

Hey by using the code snippet you can get the number of article within the category $postsInCat = get_term_by('name','NAMEOFCATEGORY','category'); $postsInCat = $postsInCat->count; echo $postsInCat; I think it help you


0

Assuming your users have three distinct Roles, you could use WP_User_Query to get a list of user IDs in each role and then use those IDs in the author__in parameter of a WP_Query: $user_args = array( 'role' => 'Role Name Here', 'fields' => 'ID' ); if ( $users = new WP_User_Query( $user_args ) ) { $query_args = array( 'author__in' ...


0

Why don't you use WP_Query. You can pass array as parameter. The array can contain category, number of posts, order etc. Then you can use the while loop to display posts and wrap them in html. Please go to http://wordpress.org and look for WP_Query for further details.


0

You can also make use of the the_posts filter and usort to sort the posts as needed. the_posts filter is unfortunately not documented You can try something like this add_filter( 'the_posts', function( $posts, $q ) { if( $q->is_main_query() && $q->is_home() ) { usort( $posts, function( $a, $b ){ return strcasecmp( ...


0

The following code is working for me. I tied in a child theme of TwentyTwelve. Just copy and replace your index.php with the following and let me know (And don't forget to change the category slug as per your database): <?php if( have_posts() ) : while( have_posts() ) : the_post(); if(in_category('aciform')) { echo ...


2

get_the_term_list() will not work here. The best function to use would be wp_get_post_terms() With the following assumption, this can work If a post only belongs to one parent, one child and/or one grandchild, you can order the terms by term_id. It is widely accepted that the parent will have a lower numbered ID than the child and the child will have a ...


0

Here is an idea. Note, this will only work if all posts are in the desired category and if all posts have only category The posts are returned in an array which you can access through $currentissue->posts With this in mind, you can get the first post ID as follows $currentissue->posts[0]->ID Now, you can add that to a variable $id = ...


2

Notice that you don't need echo to display the result, since echo=1 is the default settings of wp_get_archives(). As @PieterGoosen explained, the wp_get_archives() function doesn't support the exclude parameter. But we can use _exclude_terms, the custom parameter of the wp_get_archives() function, to exclude posts with some given terms. Here's an ...


1

You could schedule a function to be called using a cron job. http://codex.wordpress.org/Function_Reference/wp_cron When you're done, you could probably unregister the cron job from inside the function so it isn't called repeatedly.


0

You'll need to add template files to your theme as pr1nc3 linked to. WordPress will automatically load the appropriate file when the taxonomy term is requested.


0

I think your idea is really nice here, but you have a couple of serious flaws in your code. Never use extract(), ever. It is extremely hard to debug and can render unexpected output. It has now been completely removed from core, except in one instance as far as I can pick up from this core trac ticket. The codex has also been updated to reflect this ...


1

Your code won't work as there are no exclude parameter in wp_get_archives(). Here is the list of valid parameters and their defaults <?php $args = array( 'type' => 'monthly', 'limit' => '', 'format' => 'html', 'before' => '', 'after' => '', 'show_post_count' => ...


0

Alright, I solved it: I queried the year and month of the page we're on with: $year = get_query_var('year'); $monthnum = get_query_var('monthnum'); And then I added date parameters to each WP_Query: $col1 = new WP_Query( array( 'year' => $year, 'monthnum' => ...


2

You should always do the two following checks Check that your current query is the main query Check that the query is a front end query pre_get_posts alters all instances of WP_query, front end and back end, so you will need to make double sure you are doing the above checks Also is_category() should be an object of $query Your conditional should look ...


1

Check for is_main_query on the query object. if ( is_category( 'video' ) && $query->is_main_query() )


0

Please use the following code: $arg = array ( 'posts_per_page' => get_option('posts_per_page'), 'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1 ) ); $wp_query = new WP_Query($arg); if ($wp_query->have_posts()) : while ($wp_query->have_posts()) : $wp_query->the_post(); // do something endwhile; ...


-2

Please remove code: <p style="text-decoration: line-through;">$paged = (get_query_var('paged') ? get_query_var('paged') : 1);</p> Use this one: $the_query = new WP_Query("posts_per_page=10&category_name=life-sciences&paged=".**(get_query_var('paged') ? get_query_var('paged') : 1)**); ?>


0

Use a category number instead of name... i.e. query_posts('cat=1'); Looks like you have some lightbox code mixed in with your query. Not sure what exactly you are trying to do. If you don't want to use the images as bg images get rid of the... <div class="lazyOwl" style="background:url(<?php echo $src[0]; ?>) no-repeat center ...


0

Your theme doesn't necessarily include all these template files. It might just use index.php to serve the single page template as well as listings (category, date, author, tag, etc). The articles Theme Development and Template Hierarchy from the codex should get you on the right road with theme development. If you add a single.php file, WP will use that ...


1

In my opinion, you should avoid using common words like "images". It can be confusing for the system. A previous post on SO nailed the use of images using Category ID. Here's your edited code: <?php $your_category_ID = '1' $query = new WP_Query( 'cat=$your_category_ID' ); if ( $query->have_posts() ) { while ( $query->have_posts() ) : ...


0

Your query explicitly excludes the current post with this: 'post__not_in' => array($post->ID), remove that and it will return the current post within the results.


1

Here is my take on things. I have scrapped your complete idea and went with an alternative solution which doesn't use SQL. I have done some testing and found my method to be much faster that the code in your question THE IDEA: You first need to get the current post id, which I get through get_queried_object_id(). The post ID will be used to retrieve: The ...


1

On the contrary to what is suggested by the accepted answer, you should never use query_posts 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 modify main query of a page by replacing it with new ...


0

I was trying after posting here too and I got my snippet and here I am also sharing it so you can also get it. I used the code shared at Display WooCommerce Products Categories With Thumbnail & Description. It also shows Title, Link, Product Count In It, Thumbnail, Description and Custom Text so this is my solution. Hope you will find it worthy too.


2

The fields returned by get_term_by() are: term_id name slug term_group term_taxonomy_id taxonomy description parent count So instead of $thiscat->ID, you should use $thiscat->term_id Ref: http://codex.wordpress.org/Function_Reference/get_term_by


1

Not weird, there is no ID in a term object, it's term_id. You can also var_dump($thiscat) in your loop to see all of its properties.


1

As you have stated, pages aren't meant to have categories. I would rather look into custom post types and taxonomies, but the implementation is still up to you as I don't know your structures I have never tried this before, neither do I know if this will actually work, but you can try the pre_get_posts action to amend the main query to display pages on your ...


0

Maybe you should use following statement to get categories of a taxonomy: $taxonomy = 'your-taxonomy-name'; $tax_terms = get_terms($taxonomy, array('hide_empty' => false));


-1

You can use the following line of code in your category.php file for Random posts. <ul> <?php $posts = get_posts('orderby=rand&numberposts=5'); foreach($posts as $post) { ?> <li><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a> </li> <?php ...


0

There is no way to do this natively, so you will need to do this by custom functions. Here is what you will need to do: (This complete solution is based on the build-in taxonomy, category) You will need to implement a system whereby you will need to determine the current post position of the current post been viewed in the specific category. You will ...


2

As I have stated in my comments to your question Crappy written plugins always leads to some disaster at some time. In my opinion, delete that plugin and write your own code or find a properly written plugin. There is no use changing the damaged tire while the whole car is a complete write-off :-) Just to start off, never use query_posts Note: This ...


-2

you may use this way: <?php $category_id = get_cat_ID('Category Name'); <!-- Start the Loop. --> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <!-- Test if the current post is in category "Category Name". --> <!-- If it is, the div box is given the CSS class "post-cat-special". --> <!-- ...


-3

Set below code : <?php if (is_category()) { $posts = query_posts($query_string .'&orderby=title&order=asc'); } ?> You can exclude if condition if do not using category. For more reference: Alphabetizing Posts


2

Just remove the trailing comma with some good ole php before echoing it out. $thelist = rtrim($thelist, ',');


0

There's a sql script written by someone else that does the job - updates counts for product categories in woocommerce or any other category counts. Only takes a few seconds to run as well: http://stackoverflow.com/questions/18669256/how-to-update-wordpress-taxonomiescategories-tags-count-field-after-bulk-impo



Top 50 recent answers are included