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
- How to pass php array to external js file in WordPress
- Woocommerce – how can i add items to cart using onclick – multiple items at once with custom prices
- I have issue with decoding json ex. ‘{“a”:”b”}’
- JqueryUi Dialog giving Uncaught TypeError: this._addClass is not a function error
- How to place login logout link on menu that redirects users back to current page?
- Woocommerce price including tax with formatting from options
- wordpress inserting posts programatically through a url
- How does WooCommerce ensure that a product doesn’t run out of stock during payment? [closed]
- Can I change a variable in a content part while calling it?
- How do you target virtual pages in code?
- Placing the_content inside shortcode not working
- How can I add an alert (like the old javascript alerts) to my WP page?
- Why is $_REQUEST an empty array in admin-ajax.php?
- Change behavior of the tag
- Is it acceptable to treat a filter like an action?
- wp_head function not outputting
- WordPress page content outside WordPress
- Shortcode to find and replace URL
- Function Reference Documenting Template Tags for use in Custom Theme Templates?
- Seo Friendly Filter URLs
- PHP contact form not redirecting [closed]
- Add new post in existing categories using wp_insert_post
- I’m unable to call img path using single quotes in an array?
- Else/If Statement to Display Photo Descriptions
- custom header text
- Display additional page templates and a sidebar on plugin activation
- Trying to copy linux blog locally with XAMPP – php fatal error
- unsetting actions (edit and trash) of specific posts from that list of all pages or posts based on each posts metabox value
- How to search order using database frontend short code WordPress
- Categories does not show Block editor WordPress
- Foreach Loop Of Post Types With Nested If Else If Not Completing Process
- WordPress Slick Slider + Magnific Popup
- Fix common misspellings/errors based on array of replacements
- Search for single post by 2 tags
- Contactform7: display results from CURL
- How to update option field in database on clicking the publish button in customizer
- Add ID to output only for first option
- how use php query in AJAX jquery
- Custom Meta Box If Else Statement
- Static pages not being allowed
- How to set if meta_value is lower < than other meta_value in a get_posts array?
- How to insert a variable into a query parameter?
- WordPress move current to top in the loop
- How to change product SKU’s in bulk with a plugin
- BrowserSync not detecting PHP files in WordPress + Laravel Mix