get_the_tags()
returns an array of WP_Term
objects. Even if there’s only one tag, it returns an array with one item.
You can use wp_list_pluck()
to check the WP_Term
objects in the array, though, and so your code can be re-written:
function web_alert($content) {
global $wpdb; // A side note: this doesn't seem to be necessary.
$alert = get_blog_post( 2, 1 );
if (
$alert->post_status == 'publish' &&
in_array( 'my-tag', wp_list_pluck( get_the_tags( $alert ), 'name' ) )
) {
$content="<div class="alert">" . $alert->post_content . '</div>';
return $content;
}
}
add_shortcode('webalert', 'web_alert');
wp_list_pluck( get_the_tags( $alert ), 'name' )
should return an array of the post’s tag names, which you can then check for your desired tag with in_array()
.
Related Posts:
- How to use WordPress Multisite With Different Domain Names?
- Can i merge 2 new WP_Query($variable) ‘s?
- How to reliably flush rewrite rules on multisite?
- Convert a Multisite WordPress install into a Single site
- Using wp_insert_post() with Networking enabled
- Sharing Dynamic Sidebars across Multisite Blogs
- WP Multisite – multilanguage – swich to other language by click, but “same” content
- Multisite: How to store global options vs. site options?
- Hide a theme on list of themes in wp-admin without editing core files
- Lock one of WP Network sites for not registered users
- How can I manage all multisite pending comments in one place?
- WordPress Multisite Network installation and dev questions
- How properly delete only one site (blog) from the Network in WordPress Multisite (WPMU)
- List all sites in multisite
- Migrating WPMS from apache to IIS7 causes Database Error
- Turn off trackback/pingbacks and comments on all existing multisite sites
- My subsites accidentally went from one multisite network to another. How do I change it back?
- How to change a WordPress network domain
- Multisite sub-site dashboard redirects to /wp-admin/
- How to configure WordPress Multisite by bash script?
- Subfolder multisite issue. Themes and plugin files 404
- Creating Admin Options Page where users can make changes to a theme
- Creating multisite in wordpress using php
- How to use both British and American English?
- WordPress Multisite Sites show in Dropdown but not in Sites menu
- WP Multisite Static Frontpage
- Disable domain redirect
- Multisite setup on IIS with subdomains
- Partially translated dashboard in one of network’s site
- How can I fix a Virtual Multiblog install that has no errors, but won’t show all my sites?
- Depth > 2 possible with multisite?
- What are Attributes used for in a WordPress Multisite?
- Architectural reasons behind sitemeta, blogs, home, site and DOMAIN_CURRENT_SITE redundancy
- Make a user administrator to a sub directory site and a contributor to main site in multisite network
- How to store custom user data on the database?
- Redirecting non www to www ONLY for domain, subdomain without www
- wordpress multisite dashboard link in admin bar
- WordPress Multisite Question
- Multisite – user email activation links broken
- Wrong Redirect/Rewrite Rules?
- Four columns in the wp_users table
- multisite subdomain behind reverse proxy
- Is this the right set of records for Route53 domain to point to a mapped domain in a multisite? [closed]
- Multisite Subdirectory with same domain subdomain
- Initiate multisite with blog_id outside of wordpress
- What are good approaches to routing some urls to a second WordPress install?
- Show media-frame-menu on custom Media Frame
- How to run a WordPress site across multiple ccTLDs?
- Why is MySQL receiving such a large serialized object?
- How can I remove the folder from a Multisite URL?
- Google Apps SMTP for WP MultiSite?
- How to Display BuddyPress Profile Field Data In Multisite Blogs [closed]
- Set up Network Locally on a Flash Drive
- Help with multisite redirect issues using Cherokee OR solid nginx config?
- Pull Custom /wp-admin/css for Non-Admin in Multisite
- Being Forced To Use Sub-Domains on Multisite
- WordPress in subdirectory, Multisite using subdomains Nginx
- Is WordPress cache shared for all blogs in a multisite network?
- White blank page when Updating/Draft/Publishing Page/Post
- The Events Calendar: Events page as Home page [closed]
- Multisite wp-admin goes to blank screen after forwarding URL
- What is with the one month time limit for sub directory installs for multisite network?
- Can I use the same Folder name as a Multisite Blog?
- How to redirect user after session timeout
- WPMU If MU site has no administrator, deactivate site
- Choosing the right kind of hosting for a WordPress multisite
- Moving wordpress multi to different domain and vhost – cannot log in and menu problems
- Merge Multiple Sites/Networks (at least 2) into One Site/Network
- How can I run multiple unique WordPress sites off of one VPS
- Multisite Configurations
- How to update wordpress content of wordpress multi-site subdomain
- Multisite Subdomain Change
- WP-CLI Error Requesting CURL Extension
- Allowing users to manually add or remove themselves to/from WordPress multisite blogs
- Website creation for multiple clients but from a single account on multiple host name
- Is mature Multisite
- Subdomain multisite instances having same content
- Can I add a rewrite rule in htaccess to remove the multisite subdirectory from the URL?
- allow multisite in the installation process
- Error establishing a database connection after moving local wordpressmultisite from one directory to another
- Multisite domain mapping with SSL redirects to main domain
- Define a new sub-folder naming – Multisite
- How to split database of WordPress multi-site network into multiple database
- Multisite /files/ URLs broken after server move
- WordPressMU: URL change and broken permalinks/links
- Extended URLs created using multisite feature not loading CSS/JS
- Backend freezing on certain pages of a subsite
- Modifying get_author_posts_url() in Multisite
- Multisite – User creation for second site from first site?
- Get users from all/specific blog by user_role and current_user role
- How do I enable Multisite on WP 3.7.1?
- Multiple domains for with a single instal
- Pages redirect me to the homepage
- Using common slider in all sites
- Letting clients use visual builders plugins/themes on WordPress Multisite installation
- WordPressMu network with private sites
- Moving a WordPress Multisite site to a new install
- HyperDB, Multisite – on new site creation put site’s tables to specific database
- Run WordPress multisite from secondary volume on AWS EC2
- Redirect to Multisite site 2 if site 1 has a setting