I cannot get tax_query in get_posts() to work with custom taxonomy

I have been trying to achieve this for the past two days but nothing works. I am attempting to build functionality to search any post, page, and a couple other custom post-types by a tag. I have created a plugin which registers a taxonomy called search_tag. search-tags.php require_once __DIR__ . '/includes/search-tags.class.php'; function search_tags_closure() { $search_tags = new Search_Tags; $search_tags->create_taxonomy(); } add_action('init', 'search_tags_closure'); search-tags.class.php class Search_Tags { const NAME = 'search_tag'; const LABEL = 'Search Tags'; protected function get_post_types() { $args …
Category: Web

Fix wp_term_relationships slow query in get_posts

I used the Query Monitor plugin to find slow query on my WordPress site. The below-mentioned WP_Query->get_posts() takes about 0.3446 query time out of the total Database Query time of 0.3976. SELECT wp_posts.ID FROM wp_posts LEFT JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) WHERE 1=1 AND wp_posts.ID NOT IN (203598) AND ( wp_term_relationships.term_taxonomy_id IN (17) OR wp_term_relationships.term_taxonomy_id IN (11652,20693,21952,23971,24907,24908,25928) ) AND wp_posts.post_type = 'post' AND ((wp_posts.post_status = 'publish')) GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0, 6 I'm guessing it …
Category: Web

Wordpress tinyMCE Keep Wrapping <p> Tags To HTML Codes When Saving

Wordpress tinyMCE keep adding &lt;p&gt; tags when I saved my custom post types in visual mode opened! I had searching for many solutions, but not working. Here is the solution that I found, but this is unable to stop wordpress from adding annoying &lt;p&gt; tags from my html codes: Javascript: &lt;script type="text/javascript"&gt; tinyMCE.init({force_p_newlines : false}); &lt;/script&gt; PHP function tinymce_remove_root_block_tag( $init ) { $init['wpautop'] = false; $init['force_p_newlines'] = false; $init['forced_root_block'] = false; return $init; } add_filter( 'tiny_mce_before_init', 'tinymce_remove_root_block_tag' ); I don't …
Category: Web

How to "group" (categorize) the Pages together?

I have a lot of Pages which can be (need to be) grouped under a number of different Categories. ** Then the more important thing is, i need to control those pages (of different groups) programatically via functions.php. Lets say, i would have: Page A (Categorized as: Fruits) Page B (Categorized as: Vehicles) Page C (Categorized as: Vehicles) Page D (Categorized as: Fruits) Page E (Categorized as: Technology) Then from functions.php, there would be some logics, like: If Page is …
Category: Web

Include results with tags relevant to the search keyword with JSON rest API v2

Wordpress doesn't natively search for tags so I need to install WP Extended Search and add post_tags as one of its parameters so whenever I search for keywords natively, posts with that tag will appear. However, when I tried searching on the wp-json REST API, that post doesn't appear. Here's an example with a post that is tagged with &quot;technology&quot;. When I search &quot;technology &quot; using this json rest api url, it returns an empty array: example.com/posts?search=technology But if I …
Category: Web

alt, title tags not showing

I have added alt tags, title and description on all the images on my website but none are showing when I check them in the inspect element tool in chrome or firefox. Here's a screenshot: And here's the screenshot of inspect element of the same image:
Category: Web

Mass remove a number of tags from a number of posts

i am having a wallpapers site. I was having lots of posts with no tags and i tried some plugins to auto add tags like simple tags where you need to set some tags and it will auto use those tags for posts, then i used auto tag posts option and it added all the 50-60 tags to a number of individual posts,Means it added 50-60 tags to each of the posts in 500 posts. Its very time consuming now …
Topic: tags Wordpress
Category: Web

How do I add a tag slug to a category URL to filter posts?

I want to add an option to my site to filter posts by one specific tag on the category page and at the same time have a nice URL (no query strings). So something like this: https://example.com/%category%/ - standard category link (currently) https://example.com/%category%/%tag%/ - a page like the above, but displaying posts from a specific category AND tag. Is this possible? If so, how can I achieve this? I would also like to note that for posts I have such …
Category: Web

For each loop on every word in post

I'm having a recipe site where every post naturally contains ingredients. Every ingredient is a tag, and I would like to automatically link every ingredient so the user can click on it and see all recipes that uses that certain ingredient. For this to be possible I guess I have to loop through every word in the post, then check if that word is equal to an existing tag, and wrap that word in a hyperlink. But I'm not sure …
Category: Web

How to add site tags in alphabetical order to shortcode?

Good morning. There is a shortcode that displays site tags on a separate page. function tag_cloud_shortcode($atts) { extract(shortcode_atts(array( 'cat' =&gt; '' ), $atts)); $query_args = array( 'cat' =&gt; $atts, 'posts_per_page' =&gt; -1 ); $custom_query = new WP_Query( $query_args ); if ($custom_query-&gt;have_posts()) : while ($custom_query-&gt;have_posts()) : $custom_query-&gt;the_post(); $posttags = get_the_tags(); if ($posttags) { foreach($posttags as $tag) { $all_tags[] = $tag-&gt;term_id; } } endwhile; endif; $tags_arr = array_unique($all_tags); $tags_str = implode(&quot;,&quot;, $tags_arr); $args = array( 'echo' =&gt; false, 'smallest' =&gt; 10, 'largest' …
Category: Web

How can I automatically hyperlink tag names that are in my post body to the tag page

I have a number of sports sites with hundreds of thousands of existing news posts. The site also has a custom post type for team and a custom post type for person. I wish to be able to somehow automatically find team names and player names in news post body and hyperlink them to the correct team / player post. The post names exist with exact player and team names. For example Lionel Messi &lt;&lt; Player post Manchester United &lt;&lt; …
Topic: tags Wordpress
Category: Web

How to exclude labels from certain categories in a shortcode?

Good afternoon. There is a shortcode [alltags] that displays ALL site tags on a separate page of the site in alphabetical order with a letter. function wph_alltags_shortcode( $atts, $content ) { $posttags = get_tags(); $output = ''; if ( $posttags ) { $output = '&lt;dl class=&quot;alltags&quot;&gt;'; foreach ( $posttags as $tag ) { $l = mb_strtoupper( mb_substr( $tag-&gt;name, 0, 1, 'UTF-8'), 'UTF-8' ); if ( $L != $l ) { if ( $L ) $output .= '&lt;/dd&gt;'; $L = $l; …
Category: Web

Unable to get all tags from specific categories

Page in question. I'm trying to use a WP_Query(); targeting specific categories and displaying all the tags used for posts within those categories. I noticed that some tags, like truffles aren't being included in the results even though that post is categorized as a recipe and it's other category, sweets, is also included in the category array. Any thoughts on what I'm doing wrong so as to get only some of the tags? Thanks! &lt;ul class="tag-list"&gt; &lt;?php $query = new …
Category: Web

problems with alt text not appearing in source code

I have added alt tags, title and description of all the images on my website but many do not show up when I check them in the inspect element tool in chrome or FireFox. SEMRush states over 900 images do not have alt tags! For example, the image on my homepage www.medispera.com in the code it states alt="image" instead of the alt text appearing. Please advise how to fix.
Category: Web

Display all categories but only if they have posts in them that have a specific tag assigned

I have a WooCommerce site and am working on the product tag pages. I want to display every product that is assigned to that tag, and break them up into their individual categories (this bit is working). The only issue I am having is it is displaying every single category, even if 0 products in the current tag have that assigned. &lt;?php $tag_id = get_queried_object(); ?&gt; &lt;div id=&quot;product-list&quot; class=&quot;product-list&quot;&gt; &lt;?php // Get all products inside the current tag ?&gt; &lt;?php …
Category: Web

How can I remove certain HTML tags from the RSS feed?

One news aggregator wants to have RSS feed without any links into the &lt;description&gt; field. So I try to use this code in functions.php to remove &lt;a href&gt;&lt;/a&gt; tags, but it doesn’t work. What’s wrong? How can I remove the tags but keep intact all the text? add_filter('the_content', 'my_custom_feed'); function my_custom_feed( $content ){ global $post; if ( ! is_feed() ) return $content; // Remove all shortcodes $content = strip_shortcodes( $post-&gt;post_content ); $content = strip_tags( $content ); // Remove all html …
Category: Web

Using wp_tag_cloud with only current post tag with special class

I am trying to output all the tags (custom taxonomy) without link, and add special class to current post tags. For example: if there are 10 tags but current post has 3 of them applied, then it should display all the 10 tags without link but only 3 tags should have special class. I am currently using: $terms = get_the_terms( $post-&gt;ID, $tax ); $tag_list = implode(',', wp_list_pluck($terms, 'term_id') ); wp_tag_cloud( array( 'taxonomy' =&gt; $tax, 'include' =&gt; $tag_list) ); which is …
Category: Web

Is it possible to embed a wordpress tag page on wordpress?

I'm trying to use the &quot;Embed URL&quot; block to include another WP site's tag page on my WP page. It seems like I'm able to embed individual posts from that site (so the theme supports embedding) but I get the error &quot;Sorry, this content could not be embedded.&quot; when I try to use the tag page url. Is it possible to embed a tag page?
Category: Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.