You can do this:
function foo_command( $args ) {
WP_CLI::success( $args[0] );
}
WP_CLI::add_command( 'foo', 'foo_command' );
And put it in a plugin, then run:
wp foo "hello world"
And it will print out hello world.
Just because the built in subcommands don’t do what you need them to do, doesn’t mean you can’t add your own. WP CLI will take care of bootstrapping WordPress and loading things properly ( and it avoids the security issues of standalone endpoint PHP files such as the one in your question )
However, I suspect the solution to your actual problem is this:
wp post list --name="hello-world" --fields="id"
And for the REST API:
https://example.com/wp-json/wp/v2/posts/slug?="hello-world"
Related Posts:
- What is PHPSESSID?
- WordPress Themes and PHP unit
- What would be a PHP command to erase all posts from category X from the last month?
- How to insert PHP code in a WordPress Post
- Creating wordpress user registration form
- How to reduce the database query-es
- category not display in word press grammatically
- “Notice: Undefined variable: content” is showing [closed]
- How should I best target dynamically served content?
- Way to display “Yesterday”, “Today”
- Have CSS Class Added with `is_page()` WP function
- Slide in Panel WordPress Post
- Shortcode Inside Class Not Working
- Custom admin page: How to save changes specific to users
- the_title gives me the page’s title not the post title in the following code
- Category Thumbnail Display – How to display ONLY the main Category
- comments_number display outside specified span
- Using a `Template Parts` folder instead of an `Includes` folder in a Custom WordPress Theme
- class click counter save number
- Get stock by custom meta field on all Woocommerce variable products
- WP functions in .js
- How to Add Extra Search terms with WordPress Search keyword term?
- How do I add custom bulk actions to multiple custom post types?
- How to prevent XSS alter custom global javascript object & methods in WordPress
- Ubuntu Server/PHP: How do I ensure WP uses the latest PHP version on my server?
- How do I programmatically set a user as spam in BuddyPress? [closed]
- Post + form + action + results on the same page
- wordpress 4.4 self hosted video (html5) doesn’t show
- Pagination in plugin’s backend
- WordPress style.css not updating, only after theme reload
- How can i display a jquery slide on front page
- Saving zero in meta box
- How to edit php code in WordPress Post file?
- site_url and $current_user producing undesired results
- Count posts on multisite with blog id
- how to make jpg downdable in wordpress?
- Adding string before php [closed]
- Moving wordpress site from localhost to live server using GoDaddy cPanel
- Making (and edit existing) posts with ID included
- Woocommerce display one random product via php
- Change url tag name
- Help with WordPress function inside a shortcode
- Wpdb->insert() doesn’t insert new row after the last one
- InnerBlocks with allowedBlocks not working with acf_register_block
- PHP -> SQL Query with Summing
- Calling PHP Scripts in Ajax that are in PHP Snippets
- How to insert wp_users ->user login name to wp_terms when a new user registering?
- Alter Woocommerce product archive structure
- How to style injected code in header section?
- Allow user to Upload image and manipulate it on the frontend
- can’t get errors
- $wpdb->get_results breaking page?
- Echo array value
- How to break up php code to avoid echo
- Display background color or image with custom meta box?
- SQL error with custom query
- php_gd2 extension not loading on Windows
- Replace category title with category description in woocommerce
- Executing php on button press
- random post redirect in wordpress with a .php file
- “Edit comment” window add view all comments on post, how?
- Use PHP Class in WordPress functions
- If user has clicked link add class and store using PHP/WordPress
- How to put 2 php codes in functions.php without site crashing
- How to remove the replace the product image by video on shop page conditionally
- WordPress Bad Request Error 400
- How to filter specific element of an array in wordpress/php?
- Having trouble with customizing blog posts on the home page
- wordpress returns http error 500 on a fresh install
- Right path for renaming a file in uploads folder
- View tag description on page
- Add a leading zero to pagination
- WP HTTP API call response
- Fatal error when using array_diff() function inside of wp_update_nav_menu hook?
- changing static link to relative link
- wordpress ajax pagination
- Custom fields changes the formatting of metabox input
- AJAX Not Working With WordPress Database properly
- Pagination for div’s
- Masonry layout within the loop
- What is wrong with assigning values to a WP_List_Table class?
- Jetpack: Display Site Title when no Site Logo
- 500 (Internal Server Error) of external php file
- PHP call div with function
- Adding theme support for a custom header image
- Dynamic Post Type Variable echo as string?
- WordPress – show all posts + ones with specific tag
- Fix My Custom Function: Remove Automatic
- Catchable fatal error in appcloud free theme by Tokokoo
- Can I have a php site on subdirectory of WordPress?
- How would I split the results into two columns [closed]
- is there away to hide php code in wordpress not to show in PAGES
- Shortcode always at top of content
- Send a custom notification to customer on WooCommerce cancelled order status
- How to code bulk order form in wordpress
- ‘This Field is Required.’ is Not Displaying on CF7 [closed]
- Facing Problem While Running WordPress Hook For Archive, Categories, Author, Date Pages Only
- generate excerpt from the part of big text dump that contains keyword
- How to sort search result by post_title, then by post_content
- Custom Admin Menu Report for Specific User ID