New answers tagged

1

What a great question. Here is the function: function add_taxonomies_to_pages() { register_taxonomy_for_object_type( 'post_tag', 'page' ); register_taxonomy_for_object_type( 'category', 'page' ); } add_action( 'init', 'add_taxonomies_to_pages' ); Get back to winning, now.


-3

Write this in your theme's functions.php file function category_enqueue_script() { $cat_education_id = 'xx'; // category id for "education" $cat_dog_id = 'yy'; // category id for "dog" if ( is_category() && ( is_category( $cat_education_id ) || is_category( $cat_dog_id ) ) ) { wp_enqueue_script( 'my-js', 'filename.js', false ); ...


-2

As per your description ACF will be enough and easiest way to do that. Create custom fields group based on your requirements (per category) then restrict them to specific post category with ACF rules. Hope it will help you!


2

The theme uses the_excerpt() instead of the_content(). I had created a child theme before (so I don't modify the source theme directly: only the child one), so I only had to copy/paste the PHP file (archive.php) from source theme to child theme, and change the_excerpt() for the_content( __( 'Read more ›', 'my-domain' ) );


0

This is a dirty trick and I don't have a choice but to use it. Add .php at the end: /%category%/%postname%.php Some people add .html instead. Either way, it's pretty annoying though and I don't know if it's safe.


1

We can utilize the add_term_relationship action to check if the current post is already assigned as popular. add_term_relationship fires before a term is inserted. I also think that you are using the wrong hook here to send your mail on. added_term_relationship fires quite early before any error checking. You can still encounter a failure after ...


0

You can use the following code: global $post; $myposts = get_posts( 'numberposts=1&category=1' ); foreach( $myposts as $post ) : the_title(); the_content(); endforeach;


0

This is solution of your 404 links problem, Got to Settings -> Permalinks -> In 'Product permalink base' select the 'Shop base with category' option. For more you can visit, https://wordpress.org/support/topic/permalinks-404-with-custom-post-type


0

If you want to list all the available categories for a custom post type, this snippet might help you. Just use the standard get_categories() function and pass the $args relating to the taxonomy you registered for your CPT. So, if you defined your taxonomy like this: register_taxonomy( 'the_taxonomy_named_in_your_CPT' ); Then you'd show the taxonomy to ...


0

Nevermind. It turns out that this doesn’t list the parent categories anyway!


0

gmazzap's solution inspired me to write a plugin to do this. You can now filter your media by Taxonomies and Terms with the Media Library Filter plugin.


0

WordPress provide a way to define other object than just Posts : this is called custom post types. And each custom post type can have its own taxonomies, an entry in a specific taxonomy being call a "term". The default taxonomy for the default post type is a "category". So wp_set_post_terms can be used to set a category to a post, but also to set a term in ...


0

This is adapted from code someone else wrote, and which I benefitted from too long ago to know where it came from (if the person who originally wrote it is reading this, thanks again). It works for your request: <?php $catPost = get_posts('cat=888&posts_per_page=-1000'); foreach ($catPost as $post) : setup_postdata($post); ?> <a ...


0

I FINALLY figured it out. Phew. Answer is as follows: add_action( 'woocommerce_after_subcategory', 'my_add_cat_description', 12); function my_add_cat_description ($category) { $cat_id=$category->term_id; $prod_term=get_term($cat_id,'product_cat'); $term_meta = get_option( "taxonomy_$cat_id" ); echo '<div ...


2

In general you can't. ID numbers given at one site might be already used at another.


1

Add this to your args: 'taxonomies' => array( 'category' ) Should look like this- $args = array( 'post_type' => 'service', 'posts_per_page' => 8, 'paged' => $paged, 'taxonomies' => array( 'category' ), );


0

From the above Codex page, I used this: 'tax_query' => array( array( 'taxonomy' => 'people', 'field' => 'slug', 'terms' => 'bob', ), ), But changed it to this: 'tax_query' => array( array( 'taxonomy' => ...


0

You can find in inc/template-tags.php file. if ( is_category() ) { $title = sprintf( __( 'Category: %s', 'tesseract' ), single_cat_title( '', false ) ); }


0

What do u mean by: Page naming ?? If you are after a way to implement this situation, then here you go: You have 2 options: 1st Option Use 'hierarchical' => false while registering your apples post type, using register_post_type. Then, you will have the option to put apples posts, as parents and children, using the post edit ...


0

That's easy. Just use the same shortcode and in the parent attribute, place the ID of the parent category. You'll get out its sub-categories as a result: [product_categories number="12" parent="57"]


0

You can put together a very finite query with the get_posts() function. I tried to understand your SQL query and define it the way I would with native WP functionality, but could have missed some details. I have no clue if this is where you are going, or if this works, but WordPress is supposed to make things easier for you. Explore this page for more info. ...


2

SQL-wise, you only need to join to the wp_posts table once. Joining to the terms stuff will give you multiple rows, so it's probably easiest to group these and then use GROUP_CONCAT() to flatten the terms into a comma-separated string (updated to use LEFT joins): global $wpdb; $sql = $wpdb->prepare( 'SELECT p.ID, p.post_title AS Product, ...


2

cracks knuckles Alright -- so first thing is first. Working w/ WordPress Databases Read this: https://codex.wordpress.org/Class_Reference/wpdb Avoid write SQL statements outside of the $wpdb object. Avoid writing SQL statements like wp_users instead do this: $users = $wpdb->get_results( "SELECT FROM $wpdb->users" ); This will help if you ever ...


2

You could set up a custom post type with custom taxonomies and then allow people to filter the results or do a search. Failing that, perhaps an event plugin would help. It depends on how much coding you want to do or if you want to try and find a plug and play solution.


0

$category = get_the_category(); if ( $category[0]->cat_name == "featured" ) { // if first category in array is "featured", get next category in line $name = $category[1]->cat_name; $cat_id = get_cat_ID( $name ); $link = get_category_link( $cat_id ); echo '<a href="'. esc_url( $link ) .'"">'. $name .'</a>'; } ...


0

You could modify your query on pre_get_posts. Example: // I'd wouldn't hardcode the tags/category ids, but where to store and // how to retrieve those settings go beyond the scope of this question. define( 'YIVIS_EXCLUDED_TAG', 12 ); add_action( 'pre_get_posts', 'yivi_excludes_tags' ); function yivi_excludes_tags( $query ) { if ( ...


1

Custom post types are by default excluded from the main query except on taxonomy pages and custom post type archives. You can simply use pre_get_posts to correctly alter the main query (alter the query variables before the SQL query is build and executed) to your needs. Just a few notes on pre_get_posts pre_get_posts runs front end and back end queries, ...


1

I already have the same problem. So i write the function to remove uncategorized for all post. You can embed this function to plugins or themes and call it. function deleteUnCategoryForAllPost(){ global $wpdb; $result = $wpdb->query( $wpdb->prepare("delete FROM $wpdb->term_relationships where term_taxonomy_id =1 ") ); return $result; } ...


0

You can make use of wp_remove_object_terms() to remove the desired category from a post. What we will do is, run a custom query to get all the post with the associated category, and then loop through the posts and use wp_remove_object_terms() to remove the category FEW NOTES: The code is untested and might be buggy. Be sure to test this locally first If ...


1

To answer your question, get_queried_object and get_queried_object_id will give you all the info you need about most types of pages. However- if you're creating a new query in the template to change some query parameters, then you should instead be using pre_get_posts to alter the main query before it's run. Then you can just run the regular loop in your ...


0

This is the only option I have found: $current_category = single_cat_title("", false);


0

You need to modify the rewrite argument when you register your post type: $args = array( // [...] 'rewrite' => array( 'slug' => "Tours" ), ); register_post_type( mc_tours, $args );


0

You should be able to do a similar thing as described in that answer and filter the output from wp_category_dropdown using wp_dropdown_cats, but for the options instead of select eg. add_filter('wp_dropdown_cats', 'wp_dropdown_categories_multiselect'); function wp_dropdown_categories_multiselect($output) { $valuekey = 'valuekey'; // set to 'name' ...


0

Thanks @markkaplun. I solved it writing my own: <?php /** * Dropdown for 'my_tax' * @since 1.0.0 Using wp_dropdown_categories(). * @since 2.0.3 Custom code, as wp_dropdown_categories() doesn't provide * 'selected' field for multiple="multiple" */ $my_tax_terms = get_terms( 'my_tax', array('hide_empty'=>false) ); echo '<select ...


1

As the core tickets (for example https://core.trac.wordpress.org/ticket/16734) say the point of the api is to provide a dropdown and not a multiselect. IIRC in the quick edit of posts no API is being used for the category and tags multiselct. In other words, just ignore the API and write your own.


3

If you want your main query to take in account your custom post type, you can do as shown below : function add_custom_post_type_to_query( $query ) { if ( $query->is_archive() && $query->is_main_query() ) { $query->set( 'post_type', array('post', 'my_custom_post_type') ); } } add_action( 'pre_get_posts', ...


0

You need to use taxonomy.php instead of category.php Give little reading to template heirarchy on https://developer.wordpress.org/themes/basics/template-hierarchy/ All your custom posts will use taxonomy.php if you have some custom taxonomy defined. For eg: lets suppose there are two taxonomies i.e tax1 & tax2 If you want the same template for ...


0

Try removing $value = $count, you are first setting it as a string which I assume is correct to get the option value - but then straight away undoing what you've done by setting it back to $count (numerical.)



Top 50 recent answers are included