Tag Info

New answers tagged

0

Try something like this : $value = get_field('field_name'); Try whole process based on this http://www.advancedcustomfields.com/resources/how-to/filter-posts-by-custom-fields/ $value = get_field('field_name', $category->cat_ID);


1

The issue is that there is no taxonomy meta data like there is for posts. ACF taxonomy data is stored serialized in the options table, so it can't be queried like post meta can. You have to load all terms and check the data associated to each one individually. Perhaps a better solution is to create Romance, Action, & Drama parent terms, and make your ...


1

Here is a start. Create a template called content-related.php Inside that paste the following code <?php /** * The default template for displaying realted posts * * @package WordPress * @subpackage Pieter Goosen * @since pietergoosen 1.0 */ wp_reset_postdata(); global $post; // Define shared post arguments $categories = ...


1

If you can add your code, It may help for everyone. By reading you question. By default normally that get_category_link is have to work. Just use global $post before your loop. If is not work. What you have to do is. Grab the category id using your @category variable. (you can use print_r($category); or var_dump($category); after your code $category = ...


0

You can set restrictions on individual users or roles too to post to a specific category using this plugin. Restrict Categories - WordPress Plugin Edit: It's really easy to use the plugin, it might be worth the time to check the link out. However, i'll still show you how to use it. After installing the plugin, you can go into Settings > Restrict ...


2

Have you try: function my_custom_show_pages_in_category( $query ){ if( $query->is_category() && $query->is_main_query() ){ $query->set('post_type', array('post', 'page' ) ) ; } } add_action('pre_get_posts', 'my_custom_show_pages_in_category' ); See more: Codex


0

Adding a menu with category items / sub-items does the job here.


2

You should use Custom Post Type with hierarchical structure, which works same as Pages.


2

Edit If this is your goal: I want to use the Wordpress gallery to show all pictures of one category in a gallery (on a fixed page), which I do not have to update all the time by inserting the pictures manually. Then the easiest way to accomplish it is via custom page template. Create the template Copy your page.php template file, and name it ...


1

There are 3 parts to making this work. Register the post type with correct rewrite slug and archive. We add the %category% rewrite tag to the slug so we can swap in the selected category. We also specify the archive name explicitly. I've omitted the rest of the register_post_type arguments here, the rest can be as-is in your own example. 'rewrite' => ...


1

Problem is solved. Just need to add 'hide_empty' => false, to the array. Like this : wp_dropdown_categories( array ( 'orderby' => 'name', // ID of the already selected category: 'selected' => 4, 'hide_empty' => false, // If no category is selected: 'show_option_none' => 'Choose one' ) ...


0

Most probably the term was not found and $current_term returned as false: $current_term = get_term_by( 'slug', $term_slug, $taxonomyName ); $term_id = $current_term->term_id; According to the docs, get_term_by() return values are Term Row (object or array) from database. Will return false if $taxonomy does not exist or $term was not found. ...


0

Your queries are showing the same output, because they are identical Here is your first queries arguments: $args = array( 'orderby' => 'title', 'order' => 'ASC', 'posts_per_page' => 5, 'paged' => get_query_var('paged'), 'tax_query' => array( array( 'taxonomy' => 'store-category', 'field' ...


-1

Code is here: Wordpress chained categories I write the same code for categories. You can edit for your needs. I used the that js plugin: http://www.appelsiini.net/projects/chained


0

Change the cat to the category number you want. For example: "cat" => 2, Or if you know the category name you could also use: "category" =>"category_name", You should add any of the above two lines in your wp_query arguments like the one in below which is empty: $wp_query = new WP_Query( array( ...


1

Use WP_Query instead of query_posts(). $cpt_args = array( 'post_type' => 'product', 'tax_query' => array( array( 'taxonomy' => 'category', 'field' => 'slug', 'terms' => 'furniture' ) ) ); $cpt_query = new WP_Query( $cpt_args );


0

Found the answer: $categories = get_terms( 'category', array('hide_empty' => false) );


0

I have solved the issue with creating a list with http://codex.wordpress.org/Template_Tags/wp_list_categories changing style to list, then style it with CSS to my needs :) <?php $taxonomy = 'product_cat'; // get the term IDs assigned to post. $post_terms = wp_get_object_terms( $post->ID, $taxonomy, array( 'fields' => 'ids' ) ); ...


0

Untested, but I think this will do the trick! <?php // Get date Categories $date_cats = get_categories(array( 'include' => '1,2,3,4' )); // Loop through date categories foreach($date_cats as $date_cat) : // Get link of current date category $date_cat_link = get_category_link( $date_cat->cat_ID ); ?> <ul> ...


0

You can use template_include to set a specific template to a specific types of content using query_vars. Here is a example of how to set a specific single.php called single-information.php to a custom post type called information function pietergoosen_info_template_include( $original_template ) { if ( isset( $wp->query_vars['information'] ) ...


2

You can specify multiple categories within has_category like so: if ( has_category( array( 'category_1', 'category_2' ) ) { // do something } However, I am not sure if this acts as AND or OR, meaning does it require that ALL categories specified are matched, or one of the X supplied (category_1 OR category_2). In any case, your syntax should work ...


2

I remembered that once I had to do same thing and wrote a custom sql query... it was painful, as @Rarst said. However I'll post the function I wrote, and there isn't much to explain, is a complex SQL query where there is the intersection of 2 checks to get all the term of a specific taxonomy that are associated in post having a specific term in another ...


1

I will also add that this is a custom post type, but that shouldn't matter. In fact, this is your problem. By default, the Category Archive Index will only query posts from the post post-type. You need to tell WordPress to do otherwise, by adding your custom post type to the query via pre_get_posts: function wpse140419_add_cpt_to_category_archive( ...


1

I think you're making this far more difficult on yourself than you need to. Easiest Solution First, I'm a bit confused, because the page you call the "blog page" is not actually the blog page. The blog page is the blog posts index page, and the page you've linked is actually the category archive index for category ID 7. If you really want this: ...


0

You want the function in_category(), not in_cat(). And to check multiple categories you need to pass an array as a single argument (as opposed to multiple arguments): if ( is_single() && in_category( array( 3, 5, 6 ) ) )


0

Something like this should work but you haven't stated where you want to display the CPT pages for games. function display_games_archive( $query ) { if ( !is_admin() || $query->is_main_query() && is_post_type_archive( 'portcat' ) ) { $query->set( 'category__in', 'games' ); return; } } add_action( 'pre_get_posts', ...


1

On a category archive, the "queried object" will have what you need. $cat = get_queried_object(); var_dump($cat->cat_ID); You can access it by means of get_query_var(): $cat = get_query_var('cat'); var_dump($cat); You can also pull is straight from the $wp_query global: var_dump($wp_query->query_vars['cat']); All of these assume that you are ...


0

If you have access to the database tables you can do a mysql dump export of the wp_term_relationships, wp_term_taxonomy, wp_terms tables and import those into the new wordpress installation. I just did this between two WP installs with over 300 categories and it worked fine.


0

For displaying shortcodes you can use do_shortcode <?php echo do_shortcode( term_description() ); ?> For HTML the filter should be enough (what you posted worked on my install). remove_filter( 'pre_term_description', 'wp_filter_kses' );


1

add_filter( 'the_posts', 'wpse138563_add_posts' ); function wpse138563_add_posts( $posts ) { if( ! is_multisite() ) { // if we're not using Multisite, bail return; } if( is_main_site() ) { // if we're in the root site, bail return; } $country = get_bloginfo( 'name' ); // This assumes that the categories ...


0

The conditional is_* functions work on query, not on current post. In other words they tell you things about page you are on, however not about the current post. is_category() will check if current page is category archive has_category() will check if post has specific category assigned From your description I suspect you mean the latter.


1

What about using the UNION? Just an example: (SELECT * FROM $wpdb->posts (with JOIN and WHERE as needed)) UNION (SELECT * FROM $wpdb->posts (with WHERE to select pages)) GROUP BY/ORDER BY The select(s) must be in parenthesis to use an order by for the whole union result. As a second option, you can use a plugin to enable the categories and ...


1

First, you would need to parse your text file. Using fopen and fgets you can read a file line-by-line. For every line, you separate the comma-separated list of IDs by using explode. After that, it's a case of simply calling wp_set_post_categories where the post ID is the first element of the list of IDs, and the category IDs are the other elements. $fh = ...


1

Use pre_get_posts to modify the query before it is executed: function include_category( $query ) { if ( $query->is_home() && $query->is_main_query() ) { $query->set( 'cat', '17' ); } } add_action( 'pre_get_posts', 'include_category' );


0

If you only want to include posts from a specific category in the loop, you may need to alter the query by using wp_query(): http://codex.wordpress.org/Class_Reference/WP_Query Something like this: $query = new WP_Query( 'cat=17' ); // The Loop if ( $the_query->have_posts() ) { if ( have_posts() ) : while ( have_posts() ) : the_post(); ...


1

Figured it out! The code below automatically lists all categories and each categories posts! $args = array( 'number' => $number, 'orderby' => 'title', 'order' => 'ASC', 'hide_empty' => $hide_empty, 'include' => $ids ); $product_categories = get_terms( 'product_cat', $args ); $count = ...


0

Have you tried using 'single' instead of 'multiple'? (I guess the display of 'multiple' is a bit misleading. In your example I think the first / is a marker for the hiearchy. The second / is for dividing alternatives.)


1

If you select both categories for the post the_category() will display both and using multiple will make the child category display the parent relationship, so you will have the parent twice. If you want to display a link to the parent category and a link to child category select only the child category for the post and use the_category(' / ', 'multiple');. ...


0

What surprise me is that someone on May 2013, write a tutorial using extract and query_posts in same function. extract is considered a bad practice in PHP in general, and it's usage was abandoned also from WP core (it will no longer be used, but there are still extract calls in actual code). query_posts is a bad practice in WordPress world, you can read ...


0

You can use the_content filter to add content to a category. function my_category_content ($content) { global $post; if(is_single()) { if (in_category("My Category", $post->ID)) { $content .= 'Add something'; } return $content; } } add_filter('the_content', 'my_category_content'); ...


0

You could use: <?php $categories_list = get_the_category_list( __( ', ', 'twentyeleven' ) ); if(has_category()) { echo $categories_list; } ?> Here's the has_category function via the Codex.


2

You are trying to echo PHP code. Additionally you are using single and double quotes wrong. You should just fix the formatting of your echo() functions. Something like this: echo '<div id="requestsample"><a class="fancybox button" href="#contact_form_pop">Request a Sample</a><div class="fancybox-hidden" style="display: ...


0

OK here's an attempt, however I don't know the exact structure of your categories taxonomy so it may need some slight tweaking. I've updated the HTML of your form so it uses the values selected by the user, then there's a block of PHP code which runs a custom WP_Query to display the relevant posts (which you can edit to display how you like, currently it ...


0

There is a function called get_category_link() which might be helpful for you. This will be able to generate an appropriate link without having to hard-code it, except for the category name or ID. Examples from the Wordpress Codex: <?php // Get the ID of a given category $category_id = get_cat_ID( 'Category Name' ); // Get the URL of this ...


1

In my experience using 'posts_*' filters ('posts_request', 'posts_where'...) in combination with str_replace / preg_replace is unreliable and unflexible: Unreliable because if another filter modify uses one of that filters, in better case one gets unexpected results, in worst cases one gets SQL errors. Unflexible because changing an argument, e.g. ...


0

Try referencing the cat query variable like so: $custom_query = new WP_Query( array( 'cat' => get_query_var('cat') ) );


1

You could try modifying your query such that you have an array of categories to exclude and a conditional in the foreach, working similarly to the !empty(). An untested example: <!-- category list with thumbs --> <?php $terms = apply_filters( 'taxonomy-images-get-terms', '', array('taxonomy' => 'category') ); $exclude = array(1,7); //add the ...


0

I thought I'd let you know how I resolved this. After some discussion with a colleague, he made the point that adding a trailing year to the url, doesn't affect the page displayed (I haven't had time to find out the rationale for this yet) so: /category/subcat/2011/ displays the same page as /category/subcat/ This meant that I could parse the url and ...


0

A filter on pre_get_posts should do it. function hide_author_wpse_138491($qry) { $exc = 123; if ( !is_admin() && !is_singular() ) { $qry->set('author','-'.$exc); } } add_action('pre_get_posts','hide_author_wpse_138491'); This should exclude results from the author with ID = 123 on all front end pages except for "single" ...


0

The solution I arrived at is using the POST value of the submitted category title, so you always get what you entered and not what was saved before. Like so: function update_group($post_id) { $updates = array( 'ID' => 996, 'post_title' => sanitize_text_field($_POST['name']) ); wp_update_post($updates); } ...



Top 50 recent answers are included