From the WordPress Codex:
<?php $the_slug = 'my_slug'; $args = array( 'name' => $the_slug, 'post_type' => 'post', 'post_status' => 'publish', 'numberposts' => 1 ); $my_posts = get_posts($args); if( $my_posts ) : echo 'ID on the first post found ' . $my_posts[0]->ID; endif; ?>
Related Posts:
- What’s the net::ERR_HTTP2_PROTOCOL_ERROR about?
- How can I find my php.ini on wordpress?
- $wpdb->update or $wpdb->insert results in slashes being added in front of quotes
- Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 71 bytes)
- WordPress Error : Upload folder is not writable. Export and file upload features will not be functional
- WordPress child theme style.css not working
- Child theme css not overriding parent
- Prioritize Visible Content WordPress
- Get user role by ID WordPress
- do_shortcode not working
- WooCommerce action hooks and overriding templates
- Contact Form 7 – Custom Validation
- XAMPP, using port:81, cannot run localhost:81/mywebsite
- How to integrate WordPress with Angular 8 for website?
- Create a folder if it doesn’t already exist
- How to remove index.php from WordPress site URL
- CSS background images in WordPress
- WordPress visual composer not loading
- wordpress menu dropdown item not showing after first dropdown
- WordPress get_template_directory_uri() not returning https and only return http
- Replace ' and similar html codes with their correspondent character?
- How to prevent the “Confirm Form Resubmission” dialog?
- navigate back with PHP form submission
- How to fix “Headers already sent” error in PHP
- “Notice: Undefined variable”, “Notice: Undefined index”, and “Notice: Undefined offset” using PHP
- http://localhost:80 is not working on running Apache server through UniServer ZeroXIII
- How do I get PHP errors to display?
- Get the full URL in PHP
- How to force file download with PHP
- How to Set Category Page as Home Page in Prestashop
- Getting an error when I visit http://localhost
- PHP random string generator
- What are the differences in die() and exit() in PHP?
- Expected status code 200 but received 500
- Can you “compile” PHP code and upload a binary-ish file, which will just be run by the byte code interpreter?
- Invalid argument supplied for foreach()
- Remove the last character from a string
- How to prevent Browser cache for php site
- what does a .php?id=&value=value means?
- Setting up a PHP interpreter in PhpStorm
- Get Current URL in Magento and show something
- php create object without class
- Weird PHP error: ‘Can’t use function return value in write context’
- How do I get a YouTube video thumbnail from the YouTube API?
- How to call function of one php file from another php file and pass parameters to it?
- SQLSTATE[HY093]: Invalid parameter number: parameter was not defined
- Is it possible to run .php files on my local computer?
- MAMP “Apache couldn’t be started because port is in use.” AND “Can’t connect to local MySQL server through /tmp/mysql.sock
- Php include not working? function not being included
- PHP mail function doesn’t complete sending of e-mail
- Convert php array to Javascript
- phpMyAdmin ERROR: mysqli_real_connect(): (HY000/1045): Access denied for user ‘pma’@’localhost’ (using password: NO)
- Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in
- SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens on line 102
- What does MYSQLI_NUM mean and do?
- Fatal Error: Allowed Memory Size of 134217728 Bytes Exhausted (CodeIgniter + XML-RPC)
- Laravel 5 Clear Views Cache
- phpinfo() is not working on my CentOS server
- ERROR: SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it
- What does double question mark (??) operator mean in PHP
- How can I find the php.ini file used by the command line?
- What is the MM/DD/YYYY regular expression and how do I use it in php?
- Fatal error: Maximum execution time of 30 seconds exceeded
- cURL request in Laravel
- PHP array printing using a loop
- How to send to BCC address when using PHPMailer to format MIME message for Gmail API?
- Is there any way to test PHP locally without installing a server?
- PHP Redirect with POST data
- Getting the screen resolution using PHP
- PHP: fopen() Permission denied
- How should I be setting browscap.ini file
- CodeIgniter: Unable to connect to your database server using the provided settings Error Message
- Returning JSON from a PHP Script
- Can I store images in MySQL
- MySQL Daemon Failed to Start – centos 6
- How to generate .json file with PHP?
- Call to a member function on a non-object [duplicate]
- Generate PDF from HTML PHP
- Call to a member function fetch_assoc() on boolean in
[duplicate] - How to use Memcached with PHP7?
- Remove empty array elements
- select count(*) from table of mysql in php
- Auto increment in phpmyadmin
- Redirect old php link to wordpress link in .htaccess
- What is the meaning of ‘OFFSET’ => 1 (WordPress)
- WordPress custom thumbnail size
- Random Question Mark Icons In WordPress Text
- What does arg mean in WordPress
- WordPress dFactory Cookie Notice Plugin
- How to use wp_enqueue_style() in my WordPress theme?
- About 404 during WordPress installation
- “The Events Calendar” plugin by Modern Tribe in WordPress not working
- WordPress Main Menu – Hide ‘Home’ link on homepage only
- Scalable wordpress setup
- WordPress – Display Random Number Between 190-250
- I have shifted my wordpress site from one host to another, after shift the website wp-admin is not open
- Embed podcast feed in wordpress
- wordpress add_query_arg how to add multiple queries to URL
- Custom Coupon type woocommerce wordpress
- WordPress home page is blank but every other page is working fine