Part 1 – To remove the double quotes/extra characters:
Instead of trying regular expressions, since the output is somewhat predictable, I would try the following instead of the getCapitalLetters function:
function strip_cruft( $str ) {
$str = str_replace( '";s', '', $str );
$str = str_replace( '"', '', $str );
return $str;
}
Part 2 – To output a populated dropdown:
Use the above function and remember to add a value in between the opening and closing tags:
<?php foreach($posttype as $post) {
$post = strip_cruft( $post ); ?>
<option value="<?php echo esc_attr( $post ); ?>">
<?php echo esc_html( $post ); ?>
</option>
<?php } ?>
If you’d like them to be all lowercase, you can use WordPress’s sanitize_title
function.
Related Posts:
- How to loop through JSON data in wordpress WP REST API
- WP API V2 returning Invalid User ID
- Passing JSON data from WP Query into AJAX causing NULL errors
- Export all post from database to JSON only when the database gets updated
- Create a new user using WP REST API and declare meta object
- How Do I Add User Custom Field to REST API Response?
- API JSON Data in WordPress
- fetch_feed: retrieve entries in the appearing order, not chronologically
- Gutenberg custom block using only register_block_type() and HTML
- How can I export post data in xml format?
- how to decode % in app [closed]
- Upload a json file in php [closed]
- Why does running get_the_excerpt() when generating JSON file take 28 seconds vs. 599 milliseconds without it?
- How to send user data in json format to another server when user register on wordpress site in PHP
- Create dynamic pages from external JSON data without storing in Database?
- Parsing php string in jquery [closed]
- Vagrantpress + composer
- woocommerce registration form with klaviyo(don’t work with current user)
- wp_remote_get adding backslashes
- Creating a Multi-Level Associative Object Using AJAX
- Fetch post block/field data as JSON with WordPress API
- wp_enqueue_script seperately for each shortcode
- database sent to a JSON file
- Input data from email form not going to JSON file
- PHP > Scheduled Tasks > Sending daily email with dynamic API variables
- Fetching instagram api not working on wordpress
- JSON REST API WordPress only showing first 10 categories
- entire JS folder not loading in a WP theme
- Retrieve Json data and create multiple pages with it
- How to clone all WordPress Rest API end points
- PHP error with a shortcode: “no suitable wrapper” for file_get_contents
- Sending simple variable on single page to WP JSON
- Can’t pass var from php wp_ajax into ajax script : result undefined or null
- Issue with json decode in WordPress – value is not returning consistently
- How does one make a URL return dynamic JSON with custom Content Type?
- How can i send id of the currently posted form data through json response in custom wordpress plugin?
- Need help to create WordPress page that decodes a text file and publishes it in JSON format
- wp_send_json erase last value
- Complex PHP for json_encode > how to handle/output right?
- Can’t get_users info by using json_encode
- AJAX Filter WHILE Loop not working WordPress
- I want to use wordpress database in android app using json encode?
- Result from wp_send_json adds line feed
- Setting pages for posts
- Search in particular category in wordpress
- How to post data to a word press site in case of a mobile app
- Pass a PHP variable (loop-audio.php) to jQuery function (js/script.js)
- I am unable to fetch json data from wp_db
- JSON Object Value Show Undefine
- Force array to be a string [closed]
- get_body_params() is always empty in POST request
- How to enqueue structured data as file – jsonld file seems not to work
- Custom Navigation Bar JSON Syntax Error in JSON at Position 0
- REST API custom endpoints for metaboxes
- WordPress Register Block with metadata
- WordPress URL Rewrite not working
- wp_remote_get returns an error for valid URL
- Error when requesting password reset email – wp authentication
- How to do conditional publishing?
- New Plugin Review
- Create custom blocks for bootstrap
- WordPress Scheduled Event Request Blocking
- jQuery not defined
- dynamic page in WordPress
- Pagination of custom mysql in wordpress
- WordPress wpform plugin submit and get multiple checked value from checkbox [closed]
- Is it possible to create a wordpress database with php code?
- Trying to get a PHP variable defined in a custom post into a javascript file. Null value. Using wp_localize_script
- How to retrieve the sender email with wp_mail()?
- WordPress update_post_meta updating with empty meta_value field [closed]
- Call to undefined function mysql_connect() After upgrading PHP 7.1 to 7.3
- Is it save to use eval for a jQuery callback method coming from the database?
- Need oop for wordpress theme? [duplicate]
- Display Youtube Time Automate from Key
- An audio player that showcase a random song from playlist every 24h [closed]
- Use value from Ajax call in PHP function
- Image Attachments of an Array into Flexslider
- save metabox with new values _wp_page_template
- How to make sure relative URL works when site is not on root domain?
- xmlrpc how to check for errors
- display sticky post outside loop and exclude from loop
- remove specificly the last tag in all posts
- How to hide a child category and show his parent category
- PHP Warning: exif_imagetype
- How to detect and handle the time difference between server and user in WordPress?
- Posts title instead of Pages and Category titles – PHP WordPress
- If Statement is Ignored?
- How to change this ajax function to submit to the default wordpress content area instead of the custom field ‘seller notes’?
- Remove span tags from WooCommerce Downloads page
- Edit woocommerce_product_archive_description using hook
- Use Post ID in functions.php
- How to create loop inside wordpress function?
- Adding PHP to an if else loop
- How to set up an auto delete post?
- search results based on categories or custom fields
- Calling the Next category link on an archive page – WordPress
- Custom action on comment post
- Custom 404 error does not always appear
- Display biography post for today’s birthday person
- How to use url and amin-ajax.php