ACF add custom fields to categories and display

Check this page out from the ACF docs: https://www.advancedcustomfields.com/resources/get-values-from-a-taxonomy-term/ Specifically this section: “Finding the term related to the current post” <?php // load all ‘category’ terms for the post $terms = get_the_terms( get_the_ID(), ‘category’); // we will use the first term to load ACF data from if( !empty($terms) ) { $term = array_pop($terms); $custom_field = … Read more

How to use an array of categories as a dropdown?

Try this, $categories_array = array(); $categories = get_categories(); foreach( $categories as $category ){ $categories_array[] = $category->term_id; } array( ‘param_name’ => ‘category_id’, ‘type’ => ‘dropdown’, ‘value’ => $categories_array, // here I’m stuck ‘heading’ => __(‘Category filter:’, ‘overmax’), ‘description’ => ”, ‘holder’ => ‘div’, ‘class’ => ” ),

Add tag parameter to category.php

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 … Read more

How to hide category name

First of all, I wouldn’t recommend to use categories to show posts anywhere. Such approach has many consequences (it creates category archive, feeds, and so on). But if you already have such solution, then you can use get_the_categories filter and remove given category from the list. add_filter( ‘get_the_categories’, function ( $categories, $id ) { foreach … Read more

Sub category templates

I found the answer – this was in the function.php file – I just needed to update the category ID (long story): function inherit_template() { if (is_category()) { $catid = get_query_var(‘cat’); $cat = &get_category($catid); $parent = $cat->category_parent; $cat = &get_category($parent); if ($cat->cat_ID == 215) { if (file_exists(TEMPLATEPATH . ‘/category-limousin-magazine-templates.php’)) { include (TEMPLATEPATH . ‘/category-limousin-magazine-templates.php’); exit; … Read more

ajax for filtering posts by category in wordpress loops

A piece of javascript/jquery: $(“#queryMenu ul li a”).click(function(){ var currentCategory = $(this).attr(‘id’); $.ajax({ type: ‘post’, url: ‘ajax-category.php’, //sometimes I’m using bloginfo to get current path: url: ‘<?php bloginfo(‘template_url’); ?>/ajax.php’, data: { currentCategory: currentCategory }, success: function(data) { console.log(data); } }); }); Put right path in url. Use $_REQUEST[‘currentCategory’] inside ajax-category.php to get category ID…

Get posts under a category with SQL

SELECT p.ID AS postId, p.post_name, p.post_title, p.post_content, p.post_excerpt, p.post_status, p.post_type, p.post_author, p.guid, p.post_modified_gmt, (SELECT group_concat(t.name SEPARATOR ‘, ‘) FROM wp_terms t LEFT JOIN wp_term_taxonomy tt ON t.term_id = tt.term_id LEFT JOIN wp_term_relationships tr ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy = ‘category’ AND p.ID = tr.object_id ) AS category FROM `wp_posts` AS p LEFT JOIN `wp_term_relationships` … Read more