Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [get-the-id]

The tag has no usage guidance.

0
votes
1answer
25 views

How to redirect (301) trashed post to it's parent taxonomy TERM ARCHIVE instead of 404 page

I have a taxonomy called "Sports", that includes terms: Football, Rugby, Tennis... What I want to achieve is when (for instance) a post that has the term football is trashed and a visitor try access ...
0
votes
1answer
41 views

Reverse Cross-Sells (WooCommerce)

When you run get_post_meta( get_the_ID(), '_crosssell_ids',true); you get an array of all the products that the current product cross sells to. How do I reverse that? To get all the products that ...
0
votes
1answer
239 views

Global page ID variable empty error

I am creating theme and I have a need to create global variables within theme functions.php file. Currently I am doing it like this: /** * Setup globals */ global $nb_id, $nb_page; $nb_id = ...
-1
votes
1answer
30 views

Get the page ID if the page content has a shortcode

I have been trying to get the page ID of which it contains shortcode. I 'm getting null. Not sure what I'm doing wrong. function availabilty_id() { global $template_id; // Custom Query to look ...
1
vote
1answer
380 views

Call post-id from URL hash not working?

I'm trying to have a modal box open by default when calling it by its id. For example, if i enter the url www.mysite.com#post-28 (#post28 being the ID of the post) I will land with the moadal box ...
0
votes
2answers
94 views

Running Filter or Shortcode Before Query Prevents Excerpt from Showing

I've been wrestling with some code cobbled together for a function I found, first published circa 2009 and my inexperience with PHP has me at a loss. The function is designed to count episodes in a ...
1
vote
1answer
165 views

How to Use PHP Code In-Page?

I am looking to create a dynamic Add-to-Cart button. The problem is that I need my server to dynamically create the "add-to-cart" URL. Currently, I have a static example built here at this link. ...
0
votes
0answers
190 views

How to get the Clicked ID and output that ID data in another page

I am creating a WordPress theme. I created single.php, in which I have a button called "Watch Now". When "Watch Now" is clicked, it gets the ID of the current/clicked post dynamically using the ...
0
votes
2answers
4k views

Fatal error: Call to a member function get_queried_object_id()

I am trying to display shortcode using the following pattern: class callShortCode { function __construct() { global $post; $this->dos($post); } private function dos($post)...
0
votes
0answers
237 views

Function get_the_ID() doesn't return 404 and search pages

I have a large switch statement where I get all the pages using the function get_the_ID() but it doesn't work for 404 and search pages. This is my code: global $page, $paged, $post; $selectpage = ...
4
votes
1answer
838 views

get_the_ID() is working on my local development but not on staging server

Great to see a StackExchange for WP! Ok so I'm working on pulling images and dates from piklist custom post types and I got this working on my local, BUT when I move it to WPEngine I get a white page ...
0
votes
0answers
884 views

how to echo/display the custom field value in specific custom field name?

I have tried this code: <?php query_posts(array( 'meta_key' => 'custom_cat', 'meta_value' => 'creative', 'post_type' => 'page' )); ...
1
vote
2answers
359 views

Extracting the post_id via the wp_insert_post action (external db query)

i'm writing a little action plugin. everytime a new post is created, a new table should be created in an external db. The name of the table sholud reflect the post_id of the newly created post, but i ...
0
votes
1answer
1k views

Conditional using get_the_ID() not working [closed]

I'm using this script to not show title on a specific page <?php if (get_the_ID() != 50){ ?> Now I need to add another page: <?php if ((get_the_ID() != 50) || (get_the_ID() != 317)){ ?> ...
1
vote
1answer
2k views

wp_get_current_user always returns 0 continued

I have been busting my head trying to get the user ID with every piece of code possible but it always comes back "0". Not sure what I'm doing wrong. I started out using this: <?php $user_info = ...
0
votes
1answer
547 views

Wordpress returns the same Post ID every time everywhere!

There is something weird happening in a recent theme I have developed. Inside the post page when I use $post->ID and get_the_ID() it always returns the same ID which belongs to one of my posts! I'm ...
3
votes
4answers
9k views

How to get page's ID if I know the title only?

Is there an exact opposite funciton to this one: get_the_title(ID) I know there's: get_the_id() But it doesn't seem to accept any arguments. So, basically, I'm looking for something like: $...