New answers tagged

-1

You have to just define $cats null variable, so every time it reset the cat value null. and echo $cats out side of foreach loop. that's it. $categories = get_the_terms($custom_args->ID, 'veranstaltungen-category'); #define blank $cats = ""; foreach ($categories as $category) { $cats .= $category->name . ', '; ...


0

You can add comma this way <?php $post_cat = get_the_terms( $custom_args->ID, 'veranstaltungen-category' ); $result_pro_cat = ""; foreach ( $post_cat as $post_cat_key => $post_cat_value ) { $result_pro_cat .= '<a href="' . esc_url( get_category_link( $post_cat_value->term_id ) ) . '">' . $post_cat_value->name . '</a>' . ', ...


1

In this line: $cats .= $category->name . ', '; You append a name of category to variable called $cats. But you never reset this variable. So every post appends its categories to the same variable. So here’s how to fix this: <?php $categories = get_the_terms($custom_args->ID, 'veranstaltungen-category'); $cats = ''; // set empty string as ...


0

I managed to solve this issue using pre_get_termsas an action and then updating the query_vars $current_user = get_current_user_id(); $user_field = "user_".$current_user; $user_categories = get_field('post_categories', $user_field); if(in_array('category',$terms->query_vars['taxonomy'])){ $terms->query_vars['include'] = $user_categories; } ...


0

Thanks for posting that additional information. I think I understand what you're trying to accomplish now. Instead of filtering the value like you are now, all you have to do is update the field value during the migration. update_field($selector, $value, $post_id); Learn more about updating ACF field data.


1

I believe because: the_ID() : Display the ID of the current item in the WordPress Loop. and get_the_ID() : Retrieve the ID of the current item in the WordPress Loop. So the_ID() displays the post ID. Try to use get_the_ID()


0

I think all you'd need to do is change the WP_Query from $catquery = new WP_Query( 'cat=' .$category_id. '&posts_per_page=100' ); to $catquery = new WP_Query( 'post_type=property&posts_per_page=100' ); This assumes your new custom post type is registered as "property" (lowercase) - if you registered the new post type using 'Property' or '...


1

$args = array( 'orderby' => 'name', 'order' => 'ASC', 'parent' => 0 ); $categories = get_categories($args); May this will help you. Refer this link


0

What you are looking for is custom taxonomy (which has been mentioned in the comments). Which you create with the register_taxonomy() function. There is a beginners guide here if you need it. You will need to pass in an array of arguments. The most important is probably hierarchical which is true for something like categories, or false for something like ...


0

The tag template page began displaying posts for specific tags once I replaced the argument statement with the following, which is great!!: $tags = get_the_tags(); $tag = $tags[0]->name; $args = array( 'post_type' => 'post', 'post_status'=>'publish', 'category_name' => 'NEWS', 'tag_slug__and' => $tag, 'posts_per_page' =&...


1

As, much as I know about WordPress we have to ways to achieve this. First: You have to retrieve all posts written by an author an then you can fetch categories assigned to those posts. Store them in an array uniquely. $args = array('author' => $author->ID, 'posts_per_page' => -1, 'fields' => 'ids'); $authorArticles = get_posts($args); $...


1

Please check below code : add_action( 'woocommerce_single_product_summary','content_after_addtocart_button' ); function content_after_addtocart_button() { global $product; $product_title = $product->get_name(); $product_price = $product->get_price(); echo '<div class="content-section"> <a href="mailto:riccardoairone@...


0

get_categories() is just a wrapper for get_terms(), and you can use either function to get all the blog's categories which I assume are of the standard category taxonomy?; however, you can set a custom taxonomy when calling get_categories(), and one good reason to using get_categories() instead of get_terms() is that the output is always an array and not a ...


0

There category is not stored in the wp_posts but in the wp_terms-table. Please have a look here. There query should probably be more like this one: SELECT YEAR(post_date) FROM wp_posts WHERE post_status = "publish" AND ID IN ( SELECT object_id FROM wp_term_relationships WHERE term_taxonomy_id IN ( SELECT term_taxonomy_id FROM wp_term_taxonomy ...


0

Relationship between post and category is not stored in the posts table. You must extend your query for additional tables. By category id: SELECT YEAR(p.post_date) FROM {$wpdb->posts} p JOIN {$wpdb->term_relationships} tr ON tr.object_id = p.id JOIN {$wpdb->term_taxonomy} tt ON tt.term_taxonomy_id = tr.term_taxonomy_id WHERE tt.term_id = 4 AND ...


0

This is because the category-relations are not stored within the wp_posts table, but in another table named wp_term_relationships. You have to do some joins to get what you want. This should give you an array of Years with the published posts in this year. $years = $wpdb->get_results("SELECT DISTINCT YEAR($wpdb->posts.post_date) as year, COUNT($...


0

You can simplify it like this: $category = get_the_category(); $cat_parent = $category[0]->category_parent; $category = $cat_parent != 0 ? get_term($cat_parent, 'category')->slug : $category[0]->slug;


0

This is what I did, It works fine. http://example.com/wp-json/wp/v2/articles/?_embed&categories=1,2,3,4&per_page=30


0

Thanks to @bjornredemption, I used the following code snippet: $args = array('category' => $wp_query->get_queried_object_id(), 'posts_per_page' => -1, 'orderby'=> 'title', 'order' => 'ASC', 'post_type' => array( 'post', 'attachment'),'post_status' => array( 'publish', 'inherit')); $glossaryposts = get_posts( $args ); Furthermore the ...


1

Something like this should work : $args = array ( 'post_type' => array( 'post', 'attachment'), 'category' => ARTICLE_CATID ); $query = new WP_Query( $args );


0

figured it out. I spent literally days trying different code and the answer was under my nose. Lack of sleep! replace "INSERT" with "REPLACE" any tips for removing a category?


2

Redefine arguments for 'category' taxonomy ONLY: add_filter( 'get_terms_args', 'my_term_args', 10, 2 ); function my_term_args( $args, $taxonomies ) { // don't affect admin area passing back default arguments if ( is_admin() ) { return $args; } // check the taxonomy in use and redefine it's default arguments if( in_array( '...


0

Hi im not really experienced but I think you could do this with WP_Query. You can do amazing things with it but I dont know how to use it so I cant give example Edit after the minute I posted this: I think my answer is completely off topic how can I delete it?


1

This answer Count how many posts in category says to use this code $category = get_category($id); $count = $category->category_count;


0

Your problem isn't line 780 of ../wp-includes/class-wp-query.php So it's a little bit hard to help because you're not showing the actual code that's at fault. But you're probably trying to reference a post category by its data object instead of using the integer id. For example you might have something like this: $mycategory=get_category_by_slug('a-...


0

You can change your permalinks, adding some extension at the end: /%category%/%postname%.html


0

Here is a plugin that does the same. function get_posts_per_taxterm($taxonomy, $term_id ){ $posts = get_posts( array( 'posts_per_page' => -1, 'post_type' => 'post', 'orderby' => 'menu_order', 'order' => 'ASC', 'tax_query' => array( array( ...


0

I created a query, you can use this to find all the categories related to SELECT * FROM wpra_term_relationships INNER JOIN wpra_term_taxonomy ON (wpra_term_taxonomy.term_taxonomy_id=wpra_term_relationships.term_taxonomy_id AND wpra_term_taxonomy.taxonomy='category') INNER JOIN wpra_terms ON (wpra_terms.term_id=wpra_term_taxonomy.term_id ) WHERE object_id='...


0

To display a custom query in a single page you would need to create a new page template and assign that to a page. Create a file in your theme's main folder and call it multiple-categories.php Paste the following code in the file <?php /* Template Name: Multiple Categories */ get_header(); $args = array( 'cat' => '1, 5, 9', 'posts_per_page' ...


0

Put the code below in your functions.php file: function register_theme_shortcodes() { add_shortcode( 'category', /** * category shortcode function. * * @param array $atts * * @return string */ function ( $atts ) { $atts = shortcode_atts( array( ...


0

The main problem with your code is that you register [categorypost] shortcode, but you want to register it as [category]. Another problem is that your shortcode should return HTML code - the output of shortcode. And as you can see here, the get_the_category function returns an array of terms. So how to write it correctly? The easiest way will be to use ...


0

It can't generate 2 URLs for a single post. If not specified otherwise will probably take the variable /category/ from your first category. Not duplicate content. This is a common Wordpress behavior. I'm seeing this on most of the websites I've published with that URL structure - /%category%/%post_id%-%postname%.html I have also read your comment, and if ...


1

I assume you have added new permalink structure by defining Custom Permalink Structure on https://yoursite.com/wp-admin/options-permalink.php and added /%category%/%postname%/ in the custom structure field. This is the WordPress default/suggested method. After this, you need to flush the old permalink structure by saving and reloading the permalink ...


0

Can't give you fish, but I can try you to teach how to fish with a couple of pointers; hook into publish_post (good example code there) and / or post_updated in the function that is called that way, use wp_create_category (which will only create if the cat. name doesn't exist yet) and with the cat ID you get that you then call wp_set_post_categories (make ...


0

I was able to find a function that worked found here. First, I added the below code to my functions.php, which excludes the parent categories I do not want: function custom_get_the_category_list() { $categories = get_the_category(); $exclude1 = get_cat_ID( 'Parent1' ); $exclude2 = get_cat_ID( 'Parent2' ); $categories_list = ''; foreach ...


0

OK, I think I found the answer myself... As stated in the post I linked to: wp_term_taxonomy - defines the taxonomy - either tag, category, or custom taxonomy term_taxonomy_id bigint(20) unsigned NOT NULL auto_increment, term_id bigint(20) unsigned NOT NULL default 0, taxonomy varchar(32) NOT NULL default '', description longtext NOT NULL, parent bigint(20)...


0

I had the same problem but on a custom archive-product.php page which contains a custom query to get my products with only 10 results per page. I had 404 pages on shop page and categories page with the second page of pagination. After analysis, I found that the main query of WooCommerce asks for 16 results but I had only 12 products in my database. So the ...


0

yes, it is possible. add a template_redirect hook handler: add_filter('template_redirect', 'redirect_post_to_canonical_url'); function redirect_post_to_canonical_url(): void { if (!is_single()) { // do not redirect nothing else except posts return; } $canonicalLocation = get_permalink(); $requestUri = $_SERVER['REQUEST_URI']...


Top 50 recent answers are included