Tag Info

New answers tagged

0

Long story short, build a new array with the categories indexed by ID. Then you can just loop over the date-sorted IDs and do with them as you wish: $categories = get_categories(); $cats_index = $cats_dates = array(); foreach( $categories as $category ) { // Index the categories by their ID $cats_index[ $category->term_id ] = $category; ...


0

usort uses a callback function to sort an array: $categories_order = array_flip($categories_order); $categories = usort( get_categories(), function( $a, $b ) { return $categories_order( $a['term_id'] ) - $categories_order( $b['term_id'] ); }


0

Place this function in your functions.php: function adjacent_post_by_category( $category, $direction, $content ) { // Info $postIDs = array(); $currentPost = get_the_ID(); // Get posts based on category $postArray = get_posts( array( 'category' => $category, 'orderby'=>'post_date', 'order'=> 'DESC' ...


0

In your loop, you can use a variable to check, in this case $i, so the code will belong to: <?php $the_query = new WP_Query( 'showposts=7&cat=113' ); ?> <?php while ($the_query->have_posts()) : $the_query->the_post(); ?> <strong><a href="<?php the_permalink() ?>"><?php the_title(); ...


0

Unfortunately webtoure's solution didn't work so i decided to dive into Wordpress's database structure and came up with the following working code: global $wpdb; $taxonomy = 'country'; $environment = 0; function _get_term_taxonomy_id($term_id){ global $wpdb; $results = $wpdb->get_results(" SELECT tt.term_taxonomy_id FROM ...


0

You could also add in your category template file a code similar to this one: <?php if(is_category('category-slug-here') { ?> // display your HTML meta here <?php } ?> You would probably need to check for subcategories, but this should get you started if you want to take the PHP approach.


0

First, always develop with debugging enabled. That white screen will now contain error messages to help you determine the problem. Refer to the action reference to see the order in which things happen during the load process. Your plugin is loaded before the plugins_loaded action, which is when your code runs. However, note that the current user isn't ...


0

Plugins run a lot earlier than themes - you need to delay the execution using a hook: /** * Fire once WordPress is ready and conditionally hook our handler. */ function wpse_199197_init() { $user = wp_get_current_user(); $allowed_roles = array( 'author' ); if ( array_intersect( $allowed_roles, $user->roles ) ) add_filter( ...


0

I think that the whole concept of this question is a little bit wrong. The thing about custom post types is that they don't have categories like regular posts. They have taxonomies and terms. In fact regular categories are also a taxonomy for regular posts. So answering your questions, you need to know the name of the taxonomy first. The simple way is to ...


1

Look at the declaration of the function the_title(), it prints the title, if the third parameter $echo is set to TRUE which is the default: /** * Display or retrieve the current post title with optional content. * * @since 0.71 * * @param string $before Optional. Content to prepend to the title. * @param string $after Optional. Content to append to ...


0

wp_get_post_categories can only get POST categories not a custom post's categories, try this instead: $category = get_the_terms( $post->ID, 'custom-taxonomy-here' ); foreach ( $category as $cat){ echo $cat->name; } Check this link


0

If I'm understanding your requirement correctly, then the least painful way to do this is with the Term Management Tools plugin. You can reorganize your terms in the admin interface once imported. EDIT: turns out I didn't understand your requirements correctly :)


0

If you just want to list them you can use the get_terms function: $terms = get_terms( 'my_taxonomy' ); if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){ echo '<ul>'; foreach ( $terms as $term ) { echo '<li>' . $term->name . '</li>'; } echo '</ul>'; } Read the codex, it has a lot of examples: ...


1

There are quite a few steps involved here and also, with that 5000 posts figure you are mentioning, this will be an expensive task to do it through WordPress itself. However, here is what I came up with (I haven't tested this so you may wish to use it on a backup first and see if it works): global $wpdb; /* The ( 'from_term_id', 'to_term_id' ) map. */ ...


0

You mentioned you are using a custom taxonomy - therefore including the cat key in your wp_query args won't work. wp_query expects that to be the ID of a term belonging to the standard WP category taxonomy. With a custom tax you need to use the dedicated taxonomy parameters. So your args should be something like: $post_args = array( 'post_type' => ...


0

Select Custom Structure in permalinks and add /%category%/%postname%/ after your domain. Adding "/" to the category base doesn't work, you have to add a period/dot. I wrote a tutorial for this here: remove category from URL tutorial


0

Each taxonomy object will have _builtin set to 1 for native taxonomies, so check $taxonomy->_builtin in your foreach loop first before fetching the terms.


0

Here is a small snippet that will do the job. Found it here. /* * Hide Specified Categories (by ID) from administrators */ add_action( 'admin_init', 'wpse_55202_do_terms_exclusion' ); function wpse_55202_do_terms_exclusion() { //Where is the string 'author' you need to replace it with your users' role if( current_user_can('author') ) ...


0

Hereby my answer to my own post. I hope this is helpful to others too! To create the category, I used an array with the data per category needed for the function wp_insert_term. Then i looped trough that array,and used a fetch_media function that uploads the image found in the image-path given to that function, and returns an attachment ID. I then call ...


0

thanks for your answers. my code is : <?php $args = array ( 'cat' => '144,122,124,125,126', 'meta_key' => 'lastname', // Set order to ASC or DESC 'order' => 'DESC', // User 'orderby' => 'meta_value_num' for numeric meta fields 'orderby' => 'meta_value', ); $query = new WP_Query( $args ); if( $query->have_posts() ) { ...


0

First, you should stop using query_posts(). As said in the documentation: 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 instance of ...


0

To remove grand-children: <?php $args = array( 'show_option_none' => 'Make', child_of => 5, hide_empty => '0', exclude => '0', hierarchical => 1, depth => 1 ); ?> <b>Make </b><?php wp_dropdown_categories($args); ?> You need to add the hierarchical and depth parameters.


0

Here is the simplest way to display product child categories from specific parent id $parent_id = 12; // parent category id // Get child categories from parent id $get_child_category = get_terms('product_cat',array('child_of' => $parent_id)); // Filter products from child category foreach($get_child_category as $child_category){ $args = array( ...


0

The 'child_of' argument lets you select subcategories from a parent category, and a you can get the current taxonomy id to pass as the value: <?php $category_id = get_queried_object_id(); $args = array( 'hide_empty'=>1, 'depth'=>1, 'hierarchical'=> 0, 'show_count'=> 1, 'taxonomy'=> 'portfolio-types', 'child_of' ...


1

I would do something like this: $categories = get_categories($args); foreach ($categories as $category){ if ($category->parent != $get_id_parent_cat->term_id){ //Do stuff with the category } }


0

Instead of a sql query, I recommend to do it in wordpress way: $args = array( 'numberposts' => 3, 'offset' => 0, 'category' => put_your_category_id_here, 'orderby' => 'post_date', 'order' => 'DESC', 'post_type' => 'post', 'post_status' => 'publish', 'suppress_filters' => true ); $request = wp_get_recent_posts( $args, ARRAY_A ); ...


1

Just one note before I start, you should not call your post type menu, menu is a reserved term, so you might run into issues with default build in functionalities. You can, however, use the plural form menus without having to worry about issues ragarding conflicts As for your code, you are using invalid parameters, which is just simply ignored by WP_Query ...


1

There are number of possibilities here: 1- Giving users the ability to edit posts and add notes. This is not something you want to do. As it might create many issues for you. However, you can use a Wiki plugin if you want to pursue this option. 2- Enabling notes through comments. This is a better option. You can handle user comments and ask whether he ...


0

in my exemple, "CPT" stands for the slug of your custom post type. First step : Using the link of "create new CPT" to add the information of category. for exemple the result would look like http://server/wp-admin/post-new.php?post_type=CPT&category=potatoes Second step : Using the hook save_post_CPT to preset the category. it would be something like ...


1

You are wrongfully handling the WP_Query parameters. You can either use a query string type input or an array based one. Personally I much prefer the array type, so my example uses it: $category_id = (int) $child_category->term_id; $des_post_args = array( 'post_type' => 'tour', 'cat' => $category_id ); $des_post = new WP_Query( ...


0

Please add two new argument into your $args array. 1) Style with none value. See the markup section for more. 2) echo with 0(False). Now call and store the result into $categories variable and print it via printf(). Final code like: $args = array( 'taxonomy' => 'product_category', 'hide_empty' => 0, 'orderby' ...


0

You can specify the style argument as something other than the default (which is list) and it won't wrap the output in a <li>. You can then wrap it in a <div> yourself. Combine it with the echo argument if you need to check that the list isn't empty. Example: $args = array( 'taxonomy' => 'product_category', 'hide_empty' ...


0

in_category() is the incorrect function to use. This function checks that the current post object (which equates to the first post in the loop on an archive) is in the given category. The function you need is is_category() which checks that the current query is for the archive of the given category.


0

review https://codex.wordpress.org/Function_Reference/in_category vs https://codex.wordpress.org/Function_Reference/is_category to check for a category archive, use https://codex.wordpress.org/Function_Reference/is_category


0

I did this to solve the problem <?php $terms = get_the_terms( $post->cat_ID , 'product_cat' ); foreach ($terms as $term) { $term_id = $term->term_id; $term_link = get_term_link( $term, $taxonomy ); $term_name = $term->name; echo '<a class="cat-box" href="' . $term_link . '"><span ...


0

yes we can hide category by using plugin yoast seo got to advanced of seo and in that go to permalinks mark up the 1st option Strip the category base (usually /category/) from the category URL " and save its all done now



Top 50 recent answers are included