Skip to main content

Questions tagged [get-the-id]

Filter by
Sorted by
Tagged with
0 votes
1 answer
39 views

after refresh the id that shows correct in first time click, changes to 1

I made a like post type for another post type called recipe that user can toggle for like and getting back the like. I have to get the latest like id of specific single recipe when cliked on in data-...
Alipvd's user avatar
  • 3
0 votes
0 answers
43 views

How do I get a function to work in single.php

I have a code. add_action( 'init', 'njengah_change_post_date_programmatically'); function njengah_change_post_date_programmatically(){ $time = current_time('mysql'); wp_update_post( array ( ...
Guruh's user avatar
  • 3
0 votes
1 answer
1k views

get_the_ID() in the footer returns wrong value

I'm using get_the_ID() in footer.php but it returns a wrong value. It might come from any of the plugin which is altering The Loop without resetting it after with wp_reset_postdata() as mentioned in $...
Basj's user avatar
  • 85
1 vote
1 answer
246 views

Wordpress get the child pages of current page

I want to display the child pages of the current page you are on. <?php wp_list_pages('child_of=67&sort_column=menu_order&title_li=') ?> If I give the id number like above it works ...
Simó Tamás's user avatar
0 votes
0 answers
79 views

Why does my output of get_the_ID() change after a wp_query?

I use ACF. I have the following code: $args = array( "post_type" => "membership", "posts_per_page" => 1, 'meta_query' => array( 'relation' => '...
MastaBaba's user avatar
  • 311
1 vote
1 answer
289 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 ...
Charaf Web's user avatar
0 votes
1 answer
334 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 ...
Gustav Gesar's user avatar
0 votes
1 answer
1k 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 = ...
richardevcom's user avatar
-1 votes
1 answer
323 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 ...
Maqk's user avatar
  • 388
1 vote
1 answer
867 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 ...
thebigE's user avatar
  • 33
0 votes
2 answers
123 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 ...
Killinski's user avatar
1 vote
1 answer
181 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. ...
Travis Patron's user avatar
0 votes
0 answers
239 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 ...
Iftikhar uddin's user avatar
0 votes
2 answers
7k 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)...
Ari's user avatar
  • 1,187
0 votes
0 answers
307 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 = ...
Unix's user avatar
  • 625
4 votes
1 answer
1k 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 ...
tjoenz's user avatar
  • 147
0 votes
0 answers
913 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' )); ...
Lizza Faith's user avatar
1 vote
2 answers
576 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 ...
urka_mazurka's user avatar
0 votes
1 answer
2k 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)){ ?> ...
marcelo2605's user avatar
1 vote
1 answer
4k 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 = ...
Arion's user avatar
  • 35
0 votes
1 answer
900 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 ...
2hamed's user avatar
  • 380
3 votes
4 answers
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: $...
Wordpressor's user avatar
  • 5,051