How to Check if Post has Taxonomy Term

Category Image 036

Something I did not know about when working with Custom Post Types and Custom Taxonomies. Normally when checking if a regular WP Post belongs to a specific category, we can use the WordPress function in_category(). But that does not work with Custom Post Types. To check if a CPT belongs to a specific term in a Custom Taxonomy, use has_term() instead.

Check if WP Post belongs to specific category

To check if the current post belongs to a specific category, use in_category(). For example in your theme's single.php template, you can do this:

if (in_category(1)) {
	
	// post is in category with ID = 1
	
}

Here we are checking if the post belongs to category with ID = 1. You can change that to any category ID, name or slug, or an array containing multiple values.

Here is an example where mutliple categories are checked:

if (in_category('donuts')) {
	
	// post belongs to "donuts" category
	
} elseif (in_category(array('coffee', 'beer'))) {
	
	// post belongs to either "coffee" or "beer"
	
} else {
	
	// post does not belong to any of the above categories
	
}

Notice the use of an array in the elseif condition. You can specify as many categories as needed using an array of category IDs, names, or slugs.

Check if CPT belongs to specific taxonomy term

Now for the main point of this tutorial. To check if the current post belongs to a specific term in a custom taxonomy. For example, if we have a taxonomy named download_category and want to check if the current post belongs to the term combo, we can do this:

if (has_term('combo', 'download_category')) {
	
	// post belongs to "combo" in "download_category" taxonomy
	
}

When calling has_term(), the first parameter is the name of the term, and the second parameter is the name of the taxonomy.

To check multiple terms, use an array of term IDs, names, or slugs. For example:

if (has_term(array('combo', 'book', 'deal'), 'download_category')) {
	
	// post belongs to "combo", "book", or "deal" in "download_category" taxonomy
	
}

So this example will check if the current post belongs to "combo", "book", or "deal" in the "download_category" taxonomy.

Bonus Tip: Check for *any* taxonomy term

To check if the current post belongs to any term in a given taxonomy, simply leave the first parameter empty/blank. Example:

if (has_term('', 'download_category')) {
	
	// post belongs to a term in the "download_category" taxonomy
	
}

Here we are checking if the current post belongs to any term in the "download_category" taxonomy.

That's the thick and thin of it.

Bottom line is just remember:

  • Check post for category — use in_category()
  • Check post for tax term — use has_term()

5 Steps for Design Thinking

Featured Imgs 23

What Exactly Design Thinking Mean? Design thinking is both a theory and a procedure, concerned about taking care of complex issues in a profoundly client driven way. It centers around people as a matter of first importance, trying to understand individuals’ needs and encourages successful solutions to address those issues. It depends vigorously on the […]

The post 5 Steps for Design Thinking appeared first on designrfix.com.

I need help with “before insert” Trigger

Category Image 101

I'm trying to create a trigger that does two things, first take an ip that's in dot notation and run inet_aton on it and put the result in another field. Second, checks a lookup table to identify an ip range that the result of the first action falls into and enters the id of that row in the table. Do I have to break this down to separate triggers, a before insert and an after insert? This is a mysql database.

DELIMITER //
CREATE TRIGGER download_ins  BEFORE INSERT ON download 
 FOR EACH ROW begin
   declare vip varbinary(16);
   select `ADDRESS` from `download`;
   vip = inet_aton(`ADDRESS`);
   set NEW.ip_address = vip;

   declare vrefer int(25) unsigned;
   select id
  from `ip_lookup`
  where NEW.ip_address between ip_lookup.start and ip_lookup.end
  limit 1; 
  if vrefer is not null then
    set NEW.refer = vrefer;
  else
    exit;
  end if;
END; //

DELIMITER ;

Thanks in advance

Archived DaniWeb

Featured Imgs 23

Ever wonder what DaniWeb was like way back in the day?

Well now you don't have to guess.

Forums and tags have a new filter in the dropdown to list all Archived topics.

CSS fix for 100vh in mobile WebKit

Featured Imgs 23

A surprisingly common response when asking people about things they’d fix about anything in CSS, is to improve the handling of viewport units.

One thing that comes up often is how they relate to scrollbars. For example, if an element is sized to 100vw and stretches edge-to-edge, that’s fine so long as the page doesn’t have a vertical scrollbar. If it does have a vertical scrollbar, then 100vw is too wide, and the presence of that vertical scrollbar triggers a horizontal scrollbar because viewport units don’t have an elegant/optional way of handling that. So you might be hiding overflow on the body when you otherwise wouldn’t need to, for example. (Demo)

Another scenario involves mobile browsers. You might use viewport units to help you position a fixed footer along the bottom of the screen. But then browser chrome might come up (e.g. navigation, keyboard, etc), and it may cover the footer, because the mobile browser doesn’t consider anything changed about the viewport size.

Matt Smith documents this problem:

On the left, the browser navigation bar (considered browser chrome) is covering up the footer making it appear that the footer is beyond 100vh when it is not. On the right, the -webkit-fill-available property is being used rather than viewport units to fix the problem.

And a solution of sorts:

body {
  min-height: 100vh;
  /* mobile viewport bug fix */
  min-height: -webkit-fill-available;
}

Does this really work? […] I’ve had no problems with any of the tests I’ve run and I’m using this method in production right now. But I did receive a number of responses to my tweet pointing to other possible problems with using this (the effects of rotating devices, Chrome not completely ignoring the property, etc.)

It would be better to get some real cross-browser solution for this someday, but I don’t see any issues using this as an improvement. It’s weird to use a vendor-prefixed property as a progressive enhancement, but hey, the world is weird.

Direct Link to ArticlePermalink

The post CSS fix for 100vh in mobile WebKit appeared first on CSS-Tricks.

4 Sports Blogs That Broke the Mold and Gatecrashed the Mainstream

Fotolia Subscription Monthly 4685447 Xl Stock

Whether you’re a fan of boxing, the beautiful game of soccer, or America’s favorite pastime of baseball, there is a blog out there for you, with dedicated webmasters and writers who have spent years developing and fine-tuning their sites. As a homage to these heroes of the internet, we thought we would piece together a mishmash of some […]

The post 4 Sports Blogs That Broke the Mold and Gatecrashed the Mainstream appeared first on WPArena.

Discoverability with infinite scroll

Featured Imgs 11

How do you handle your link discoverability when also using infinite scroll.

As we know, Google has been ignoring link rel=prev/next for years.

A lot of my older content is showing up with no internal links.

I do have HTML page navigation but its hidden with display:none

Google Patches Critical Vulnerability in Site Kit Plugin

Wp Plugins

In late April Wordfence discovered a critical vulnerability in Google’s Site Kit plugin for WordPress that would make it possible for any user on the site to gain full access to the Google Search Console without verifying ownership. Google patched the vulnerability and released the fix in version 1.8.0 on May 7, 2020.

Wordfence published a timeline of the vulnerability, describing it as a proxySetupURL disclosure:

In order to establish the first connection with Site Kit and Google Search Console, the plugin generates a proxySetupURL that is used to redirect a site’s administrator to Google OAuth and run the site owner verification process through a proxy. Due to the lack of capability checks on the admin_enqueue_scripts action, the proxySetupURL was displayed as part of the HTML source code of admin pages to any authenticated user accessing the /wp-admin dashboard.

The other Aspect of the vulnerability is related to the site ownership verification request, which used a registered admin action that was missing capability checks. As a result, any authenticated WordPress user was capable of initiating the request.

Wordfence identified several ways a malicious attacker might use this vulnerability to the detriment of the site’s ranking and reputation, including manipulating search engine results, requesting removal of a competitor’s URLs from the search engine, modifying sitemaps, viewing performance data, and more.

The security fixes are not detailed in the plugin’s changelog on GitHub. It does, however, include a note at the top that states, “This release includes security fixes. An update is strongly recommended.” Google has not published a post to notify users on the news section of the plugin’s official website. Without Wordfence’s public disclosure, users may not know about the importance of the update.

Google’s Site Kit plugin has more than 400,000 active installs, according to WordPress.org. Details of the 1.8.0 update are not available to users in the admin, since the plugin’s changelog is hosted on GitHub. There is no way for users to know that the update includes security fixes without clicking through to research. Due to the great deal of sensitive information to which attackers could gain access, users are advised to update the plugin as soon as possible.

10 Most Valuable Networking Skills for Every Professional

Category Image 006
The best careers are built around the best networks. Great connections can provide you with learning opportunities, promotional opportunities, jobs, and more. The wrong connections, on the other hand, can drag your career down to their level of mediocrity. This makes it essential to develop strong networking skills so you can build the right network for your career.

Top 3 Free WordPress File Download Management Plugins

Wp Plugins

Running a WordPress website involves both content organization and WordPress file download management. If you care about your site and digital products, you should be aware of the importance of file download management and protection. There are numerous plugins allowing you to provide the file downloads for users without much hassle. Download Monitor, WordPress Download […]

The post Top 3 Free WordPress File Download Management Plugins appeared first on WPArena.

Replacing variable name in excel

Category Image 101

Hi all,
Before I begin this question, and before you tell me we dont do homework, I would like to state that I have read a few articles, I have tried a couple of functions (=REPLACE, =SUBSTITUTE) but i'm not able to get the reuslts require, I'm new to Excel
Question: Useappropriate text functions to shorten the variable names to something like Arizona Females Young, Arizona Females Old, and Arizona Females All, also is there a way to do it automatically for all variables in 1 function. The screenshot is attached.
It is kind of urgent (I understand people help within their own time).
Thanks in advance.

excel.png

Rapidops Announces API Accelerator for Enterprise Resource Planning

Featured Imgs 23

Rapidops Inc. today announced its innovative new API Accelerator to rejuvenate legacy ERP systems. Changing ERP systems is not necessary today, and not viable in most cases due to the high switching costs and the time-consuming endeavor that is fraught with business risks. The ERP becomes a piece of the technology platform, not the platform itself. Rapidops has deployed API/ERP solutions in many middle-market companies allowing maximum innovation to occur without business disruption.

Noindex AMP pages?

Featured Imgs 11

Is it appropriate to noindex AMP pages whose desktop canonicals are noindexed?

Currently, my valid but low-quality pages are noindexed. They point to an amphtml version, and that AMP page is noindexed as well.