New answers tagged

0

As of Wordpress 4.4, the add_term_meta() and get_term_meta() functions have been added. This means that the code as provided by MxmastaMills can be updated to use a far less hacky approach. Here is my update of it. There is only one field as I wanted to add a custom title, but it'll work the same for all the fields you want to add. function ...


0

I think @Lafif Astahdziq was on the right track - I like his approach even though it is fairly static. Here is how I rewrote it: add_filter('get_the_terms', 'hide_categories_terms', 10, 3); function hide_categories_terms($terms, $post_id, $taxonomy){ // define which category IDs you want to hide $excludeIDs = array(6); // get all the terms ...


0

Try this code <div class="container"> <!-- Example row of columns --> <div class="row front-posts"> <?php if ( have_posts() ) : ?> <?php while ( have_posts() ) : the_post(); ?> <div class="line2"></div> <?php endwhile; ?> <?php endif; ?> <?php wp_reset_query(); ?> <!-- Start ...


0

From the WP-Admin. Click on Appearance > Menus In the top right, click "Screen Options" Select (check) "CSS Classes" Then you will have added the optional "CSS CLASSES" to each menu item.


0

No, you cannot (easily) choose what tag ID is assigned. It's not random - it's the next ID available after the last one that was created in the database. If you really want to control tag IDs, you'll need to clear your database and start fresh, and create each tag in the order you want their IDs to be (and you won't be able to change them afterwards without ...


0

I'd set up... Teams and Tournaments as taxonomies Players and Managers as post types. If you link the taxonomies to both post types you will be able to link both Players and Managers to the same Team or Tournament. CPT UI is a pretty good plugin to help create and manage custom post types.


0

If you create your own shortcode based on the product category shortcode function duck_product_categories( $atts ) { global $woocommerce_loop; $atts = shortcode_atts( array( 'number' => null, 'orderby' => 'name', 'order' => 'ASC', 'columns' => '4', '...


0

Turns out what I needed is to use "in_category" NOT "is_category". Here is the solution: <?php if (in_category(7)) { echo 'yes'; } else { echo 'no'; } ?>


1

If you want to check whether a certain post has a certain category, you need in_category, so your test would need to be: if (in_category($category_name))


6

Here's a script that you can enqueue into your admin panel. It will add a new tab to the category tabs called "Active". Whenever a checkbox is checked, it gets added to the "Active" tab list, you can also click links in the "Active" tab list to remove them ( uncheck them ). Add this as an external script, custom-tabs.js maybe: jQuery( document ).ready( ...


0

The easiest way would be to add a meta box and use get_the_category_list to show the categories that already have been selected. This only works if you save your post, just like the tags are only shown in their own box after you confirmed them. If you want to do this on the fly, you will need javascript to fill your metabox. Put a selector on all checkboxes ...


0

With get_term_children you are retrieving a flat array of all child terms. What you want is an array with only the first child terms. Unfortunately there is no immediate way to retrieve this, so it has to be done in two steps: $parent_term = get_term_by('slug', 'bedroom', 'your_taxonomy_slug'); This gives you the 'bedroom' taxonomy term. Now you can use ...


0

get_categories function will return an array of objects, each object a category. You can read more about it here: https://developer.wordpress.org/reference/functions/get_categories/ Edit And example, as Tim Malone mentioned in the comment there are examples on that page. But here is a simple one for you, that will display your categories in a list. $...


0

You can create a template page and use the WP loop: taxonomy-{taxonomy}-{term}.php https://developer.wordpress.org/themes/template-files-section/taxonomy-templates/ Or you can use the get_posts functionality: https://codex.wordpress.org/Template_Tags/get_posts#Taxonomy_Parameters Something like this maybe: <?php $args = array( '...


0

I Believe this are the Custom Post type of wordpress. Custom post type will work in same way as the post is working, you can make different category for each post type and also will able to create different archive and single page. I am posting a sample post type code if you want to experiment more on this. This code you simply copy and past into function....


0

WordPress Core post types are post and page that are visible in the admin menu. Other than these can be either a registered custom post type or a menu page. A menu page can be added with the add_menu_page() function, and a similar thing can be done using register_post_type(), where a registered post type gets its own menu item where the following arguments ...


0

I'd say register a custom post type, eg. cat_image, so the images can be uploaded to a post using the existing featured image metabox. You could sync the data using wp_insert_post matching the widget ID to the custom post slug..? // to match widget to an existing custom post // similar to get_post but can use slug (if no post parents) $slug = $instance['id'...


-1

If you have a lot of tags this is going to be pretty inefficient, but still, it should get the job done... This first part is a little pointless but it will pare down to posts in the category that actually have tags. add_action('pre_get_posts', 'get_category_tag_posts'); function get_category_tag_posts($q) { if ( !is_admin() && $q->...


4

In addition to the answer by Tim, one can always use a proper tax_query. All the build in tag and category parameters gets converted to a proper tax_query before being passed to the WP_Tax_Query class to build the JOIN clause for the SQL query. I use a tax_query in almost all applications as it gives one a lot of flexibilty, specially when it comes to child ...


1

You need to pass more query arguments. In this case you need: $args = array( 'post_type' => 'post', 'posts_per_page' => $instance['limit'], 'category__in' => $id ); Where $id is the category id, not the post id.


4

From a quick look at the documentation for get_posts(), it doesn't look like you can exclude a post based on its category. EDIT: Actually, thanks to AntonChanning, turns out you can - just add &cat=-1 to your argument string, where 1 is the ID of the category you wish to exclude: $postslist = get_posts('numberposts=1&order=DESC&orderby=date&...


3

There really is no sane way to accomplish this, specially if you have posts that are assigned to more than one tag (which is almost always the case). What is very sure, you have you work cut out for you. Here are some thought and ideas you can persue: POSTS WITH MULTIPLE TERMS If posts have more than one tag (or any term for that matter) assigned to them, ...


0

To answer your second question: get_categories() allows you to pass a whole bunch of arguments, one of which happens to be child categories. First get the parent category. I've used get_category_by_slug here, but you could use any other way to get it, for instance Yoasts function to retrieve the primary category. $category = get_category_by_slug( 'category-...


0

Currently you are looping through the array of categories retrieved with get_the_category() and for each category you retrieve two posts. In stead I understand you want to pull two posts from one category only. To do so, you would have to remove the foreach loop and in stead define $category as the first category in the array only, like this: $category = $...


-3

<?php // Display blog posts on any page @ http://m0n.co/l $temp = $wp_query; $wp_query= null; $wp_query = new WP_Query(); $wp_query->query('cat=4&showposts=2' . '&paged='.$paged); while ($wp_query->have_posts()) : $wp_query->the_post(); ?> <div class="col-md-6 col-post-blog wow fadeInUp"> <div class="post-...


-1

As per the WP Query Codex page all you need to do is change your wp query to this: $wp_query = new WP_Query( array( 'cat' => $cat_id ) );


0

$categories = get_categories( array( 'child_of' => 10 ); foreach ( $categories as $category ) { $args = array( 'posts_per_page' => 5, 'offset' => 0, 'category' => category , 'category_name' => '', 'orderby' => 'date', 'order' => 'DESC', ...


0

Like Ash was saying, something like this using $_REQUEST or $_POST will do it. <?php $args['exclude'] = "12,20"; // omit these two categories $categories = get_categories($args); ?> <select class="selectpicker btn-block" name="coupon_cat" id="category"> <option value="">Категори Сонгох</option> <!-- if nothing else is ...


0

You can check with $_REQUEST['coupon_cat'], Which gives value of selected category then compare it with your loop value so, you can make it selected. $_REQUEST['coupon_cat'] will help you.


1

The function get_the_category is returning you an array of objects (see codex for more info), so if the post has more than one term assigned, then you are just outputting the first one. So I think that doing a foreach loop will solve your problem: foreach ($category as $cat) { if ($cat->slug != 'featured') { echo esc_html($cat->slug); ...


0

If I were you I would print_r($category) and make sure it is giving you ID's and not slugs. Also, you are submitting $category to both product_cat and brands. If your field type were slug instead of id, and terms were exactly the same in both product_cat and brands then this would work... though it doesn't make sense in the grand scheme of things. Your ID'...


-2

This is an old plugin, but I think you will get idea from this plugin Similar thing is possible with this plugin, you will find more details in plugin description. Alternatively you can use "pre_get_posts" action in your theme's functions.php file to call only on category archive page using below code. Below code will add filter on the category.php page ...


5

Suppose articles is slug of the category. 1. Add a custom rewrite rule: add_action('init', function() { add_rewrite_rule('^articles/([^/]+)/?$', 'index.php?name=$matches[1]', 'top'); }, 10, 0); 2. Filter the post link: add_filter('post_link', function($post_link, $post, $leave_name = false, $sample = false) { if ( has_category('articles', $post) ...


0

I created the following, fairly simple function in order to make the pages a higher importance than categories when loading the content. (Note: this may not the best, but a simple way. I found an issue, when using the Advanced Custom Fields plugin, it doesn't insert the custom fields neither of the old, nor of the new page by default. Adding ...



Top 50 recent answers are included