You have a few options to assign that value into $string
but ill show two
First using regular if
$string = '';
if (!empty($_GET['category']) {
$string = $_GET['category'];
}
Second using ternary operator
$string = !empty($_GET['category']) ? $_GET['category'] : '';
When working with data that you receive from outer sources, for example, inputs, url etc… its always best to validate and sanitize it.
For the sake of keeping this answer clean ill only include the function that is used for validation/sanitization of $_GET
or $_POST
filter_input
Related Posts:
- Pass media upload value to input field
- What does the token %1$s in WordPress represent [closed]
- Experiences with compiling WordPress using Hip Hop?
- WordPress redirect to landing page if not logged in
- PHP/Manual use of images? – 2 Questions
- Debugging upload problem: What part of WP does actual image-resizing?
- Remove class that has been added by parent theme
- How to use a frontend URL with a Plugin
- Get list of shortcodes from content
- Adding Google Analytics code to the tag of specific pages
- Site Health : An active PHP session was detected
- login wp impossible
- Custom image upload
- How to scale image with equal width and height without distortion?
- Create Logout Link WordPress Admin Menu
- PHP 5.5, w3 Total Cache, and opcache [closed]
- How do I add text in a shortcode?
- How to display php source code inside a post using visual editor?
- PHP in post content [closed]
- Display post image with fancybox
- Attaching a pdf to Contact Form 7 e-mail via functions.php [closed]
- WordPress – how to replace with string on the_content() in single.php
- Getting array of customizer settings
- Ajax – Call to undefined function get_option()
- Display PHP within HTML values
- Show full posts in archive
- Is there a WordPress version that is incompatible with PHP 5.3?
- WordPress 3.2 query_posts and pagination, permalinks issue
- User management system similar to wordpress one?
- Implement One Time URL Script
- Call to undefined function wp() in wp-blog-header.php
- How does WordPress know wich language is chosen when there is a database connection error
- populate form fields in a loop with ajax
- How to pass Select value from Javascript to PHP to generate select option on change
- Recent Posts Not Showing Only On A Specific Category Page [closed]
- Contact form won’t submit
- Parse error: syntax error, unexpected ‘}’ surrounding a while
- Shortcode with PHP issue “Undefined index”
- Using same variable names in files added with get_template_part()
- Custom PHP script throws critical error ONLY when editing page
- Override a function defined in wp-includes/comment-template.php
- Querying Database with wpdb
- Is it possible to define variables in a wordpress shortcode, and then call the shortcode using a specific variable?
- How can i count the post added in relationship field, theme display
- php esc_html_e with an html link inside not working
- How to get the last category name of a child category?
- How can I add a UTM tag with PHP code to pick up the post slug dynamically in the UTM?
- the_posts_pagination() not working in wpquery
- Using ob_start and ob_get_clean with wordpress shortcode
- Custom meta box values are not getting saved for my custom post type
- get post id from wp_insert_post for get_template_part
- Send notification email to admin for every new post published
- Custom Taxonomy Select Menu: Setting default option value?
- How to add author’s posts link (HTML + PHP) inside a function to output it
- Accidentally deleted php code in WordPress website [closed]
- How to extract information from a wp_query result?
- WordPress Twenty Eleven PhP – forcing php code to skip first post on homepage?
- Cloning add_settings_field() with jQuery
- How to get the second slug of a page url?
- custom add note meta box with add button in wordpress
- Display Sibling WooCommerce Product Categories on Archive Page
- Problem with data collection in tables
- How to set value selected using select2 jquery plugin
- how to get sentence values from wordpress shortcode parameter?
- Disable send password change email to user wordpress
- Using ACF Relationship field to set post type to draft or published status
- Add custom HTML data to Contact Form 7 mail?
- How to update ticket price programatically when adding to cart and checkout in woocommerce
- How to use wp_get_attachment_image or wp_get_attachment_image_src instead of $instance[‘single_feature_image_uri’]
- Query by pagename not Working
- How can i avoid duplicate same post in wp?
- Fatal error: Uncaught Error: Class ‘WP_Block_Styles_Registry’
- AJAX and custom pages
- Custom meta box is not displaying value showing tag as empty
- Replace header with large image on home page only, using Genesis child theme
- Posts in two different columns Bootstrap
- Redirecting the lost password page request when using a custon login page
- How to make a vote in the poll for registered users?
- Running local copy of an old WordPress site on MAMP
- Add class for the_post_thumbnail_caption()
- Customizing WooCommerce with PHP
- Undefined variable & issue with smof_data
- Form not working as it should in WordPress, but in a normal HTML site it does
- Pagination reset problem
- Use get_option with $emailTo on contact page
- Adding ID to a Listing but not inside WP_Query while
- PHP in WordPress?
- Child theme not working properly
- Where to place PHP for shortcodes
- Hide a div from a particular page and single pages in WordPress
- How do I create a single WordPress page that will use PHP to include different HTML files based on a vaule in the URL?
- Create a custom page URL
- Facebook php sdk 4 getSessionFromRedirect() always null
- Particular meta tag – viewport – insertion when dealing with plugin
- Getting custom field data from cart page to checkout page in woocomerce [closed]
- php grabbing every post made?
- Running a php code after User clicks a button? [closed]
- How to add Paragraph Tags in WordPress using Visual Composer?
- PHP – Multiple variables in insert post array
- Search custom post type posts only by meta fields?