Skip to main content
added 81 characters in body
Source Link
birgire
  • 67.8k
  • 7
  • 119
  • 251

I guess you're not after the current post/page ID, but rather trying to find the ID for some url from your site.

Then you should try out the handy url_to_postid() WordPress core function.

It returns the post/page ID if it exists, else 0.

Example:

echo url_to_postid( 'http://example.com/2014/11/14/hello-world' );

// Outputs the post ID as 1 in this example.

Update:

Reply to the comments: You could create a custom field, called e.g. url_offer, from the backend

Example for a custom field

and use:

$url_offer = get_post_meta( get_the_ID() , 'url_offer', true );

to retrieve it on the front end.

I guess you're not after the current post/page ID, but rather trying to find the ID for some url from your site.

Then you should try out the handy url_to_postid() WordPress core function.

It returns the post/page ID if it exists, else 0.

Example:

echo url_to_postid( 'http://example.com/2014/11/14/hello-world' );

// Outputs the post ID as 1 in this example.

Update:

Reply to the comments: You could create a custom field, called e.g. url_offer, from the backend and use:

$url_offer = get_post_meta( get_the_ID() , 'url_offer', true );

to retrieve it on the front end.

I guess you're not after the current post/page ID, but rather trying to find the ID for some url from your site.

Then you should try out the handy url_to_postid() WordPress core function.

It returns the post/page ID if it exists, else 0.

Example:

echo url_to_postid( 'http://example.com/2014/11/14/hello-world' );

// Outputs the post ID as 1 in this example.

Update:

Reply to the comments: You could create a custom field, called e.g. url_offer, from the backend

Example for a custom field

and use:

$url_offer = get_post_meta( get_the_ID() , 'url_offer', true );

to retrieve it on the front end.

added 238 characters in body
Source Link
birgire
  • 67.8k
  • 7
  • 119
  • 251

I guess you're not after the current post/page ID, but rather trying to find the ID for some url from your site.

Then you should try out the handy url_to_postid() WordPress core function.

It returns the post/page ID if it exists, else 0.

Example:

echo url_to_postid( 'http://example.com/2014/11/14/hello-world' );

// Outputs the post ID as 1 in this example.

Update:

Reply to the comments: You could create a custom field, called e.g. url_offer, from the backend and use:

$url_offer = get_post_meta( get_the_ID() , 'url_offer', true );

to retrieve it on the front end.

I guess you're not after the current post/page ID, but rather trying to find the ID for some url from your site.

Then you should try out the handy url_to_postid() WordPress core function.

It returns the post/page ID if it exists, else 0.

Example:

echo url_to_postid( 'http://example.com/2014/11/14/hello-world' );

// Outputs the post ID as 1 in this example.

I guess you're not after the current post/page ID, but rather trying to find the ID for some url from your site.

Then you should try out the handy url_to_postid() WordPress core function.

It returns the post/page ID if it exists, else 0.

Example:

echo url_to_postid( 'http://example.com/2014/11/14/hello-world' );

// Outputs the post ID as 1 in this example.

Update:

Reply to the comments: You could create a custom field, called e.g. url_offer, from the backend and use:

$url_offer = get_post_meta( get_the_ID() , 'url_offer', true );

to retrieve it on the front end.

added 52 characters in body
Source Link
birgire
  • 67.8k
  • 7
  • 119
  • 251

I guess you're not after the current post/page ID, but rather trying to find the post ID for some post url from your site.

Then you should try out the handy url_to_postid() WordPress core function.

It returns the post/page ID if it exists, else 0.

Example:

echo url_to_postid( 'http://example.com/2014/11/14/hello-world' );

// Outputs the post ID as 1 in this example.

I guess you're not after the current post ID, but rather trying to find the post ID for some post url from your site.

Then you should try out the handy url_to_postid() WordPress core function.

Example:

echo url_to_postid( 'http://example.com/2014/11/14/hello-world' );

// Outputs the post ID as 1 in this example.

I guess you're not after the current post/page ID, but rather trying to find the ID for some url from your site.

Then you should try out the handy url_to_postid() WordPress core function.

It returns the post/page ID if it exists, else 0.

Example:

echo url_to_postid( 'http://example.com/2014/11/14/hello-world' );

// Outputs the post ID as 1 in this example.
added 52 characters in body
Source Link
birgire
  • 67.8k
  • 7
  • 119
  • 251
Loading
Source Link
birgire
  • 67.8k
  • 7
  • 119
  • 251
Loading