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:
- Show div only if product has attribute
- WCFM Custom form
- Understanding responsive imagery
- Custom HTML/CSS Theme into WordPress – SEO considerations
- Stop breadcrumb function retrieving custom post type template name
- Dynamic Email Handler with ‘header (“Location: …’
- what is %variable% in a wordpress plugin? [closed]
- Grabbing value of input field inside of array
- Alternative to php echo within code
- Create guest author page via php
- Login user into magento using wordpress account
- Implement OAuth2 in custom plugin
- Slug not being updated using wp_insert_post
- Gutenberg – render_callback does not pass ToggleControl value on frontend
- save array of objects with update_option
- Remove post image caption from post_excerpt();
- What is the best way to reset the site? Different fails while set up
- How do I run the following script from my articles page?
- Failed opening required in PHP
- How to Set Page Pagination Using Ajax JQuery – WordPress
- Prevent users from display default wordpress login form
- login redirect based on user role not work as expected
- redirect user from login page if is logged
- How to pass and validate nonce in custom REST routes
- hello can you advise how to fix the error?
- How to set variable to specific field when querying
- Detecting charcater encoding for wp-config.php file
- Add multiple HTML attributes to an Elementor button
- Redirect users by role to custom pages
- How to hide header and footer from page template
- How to customize content-video.php file in wordpress as is in html file?
- How to lock users account until approvation
- Create custom table for wordpress custom registration flow
- Customize the summary table of an order in the email
- How to get a database field value from a WordPress table? [closed]
- Hide child of parent categories already hidden with “get_terms_args” – Woocommerce
- rest_cannot_create_user – Sorry, you are not allowed to create new users. CURL WORDPRESS REST API
- Divi – add title to mobile menu button
- WooCommerce: write featured image dimensions to custom fields in product’
- The search doesn’t work properly
- Having trouble customizing toolbar on wp_editor
- Cannot install plugins or themes on new WordPress installation at Cloudways
- Changing WP_MEMORY_LIMIT doesn’t affect actual memory limit
- Search results always returns “No results” no matter what
- Load wp_editor on button click
- Custom WP LIST Table filter
- Add attribute to featured image with filter (wp_get_attachment_image_attributes)
- How to enqueue structured data as file – jsonld file seems not to work
- Custom WordPress Function – Adding items from Foreach Loop into an array and Updating Field based on array of IDs (ACF + WooCommerce)
- How can I save a user’s Contact Form 7 inputs as separate columns in a custom WordPress table?
- Query posts by custom taxonomy slug in WP REST API?
- How can I change the URL via add_rewrite_rule()
- oneOf JSON Schema validation not properly working for custom post meta value?
- Suddenly sessions and header location not working
- Custom Navigation Bar JSON Syntax Error in JSON at Position 0
- Variable ++ in query loop
- Generate and upload screenshot as featured image for user-submitted post
- How to conditionally concatenate and translate two very long strings?
- Create custom API endpoint to change custom header image
- Should I use include(_once) or require(_once) for loading php-file with customizer settings?
- How can precision be improved for the debug log timestamp?
- WordPress online courses system
- How to create a WordPress PAGE in another folder?
- bloginfo url in javascript
- 404 after removing “category” base in wordpress
- How do I edit the text in this function.php file?
- Is there a way to get wp_editor (tinymce) content?
- How to align buttons properly [closed]
- index.php file keeps redirecting to a non-existent index.html file?
- how to indicate on post listing title if user already liked this post
- How to limit the number of posts in the wordpress loop in conjunction with the “download more” button?
- wordpress – page not loading (404) even if it’s there
- How to pass parameter to another url?
- How to add Paragraph Tags in WordPress using Visual Composer?
- HTTP 500 Error after Creating Shortcode
- Show button in header when product custom field is not empty
- How to make WordPress search.php display all strings found on pages or posts
- if is specific custom post in cpt
- seo meta description issue in google search
- PHP – Multiple variables in insert post array
- Getting invalid user ID error when creating a new user with wp_insert_user
- get second ID from array
- Exclude Everywhere but Admin Area?
- Why a class property becomes empty?
- Use URL query string in img src attribute
- how to goto specific page number including title with permalink
- Pull latest Youtube Video from json url and make new post
- How to extract URLs from wordpress taxonomies
- Redirect loop upon installation of my plugin
- get_the_term_list give me a whitespace
- advanced custom fields: repeater field within conditional statement [closed]
- Getting a specific “title for a section” only on Startpage?
- Find owner of coupon
- Add topbar to static html page
- Hide category by tag
- Warning: Illegal string offset ‘post’ and ‘page’
- please on skin.php on theme wordpress option fix on theme option to not print empty variables and empty
- Execute multiple PHP Snippets causes error?
- Social Sharing Buttons in Recent Articles List
- Edit Error Page style