Getting wrong ID
Getting wrong ID
Getting wrong ID
So here’s what I did to resolve this… I inserted the following code right after the loop started: <?php global $post; if( is_singular() && is_main_query() && $post->post_type === ‘download’ ) { $download = new EDD_Download( $post->ID ); $files = $download->get_files( ); $submission_attachment_ids=””; if ( is_array( $files ) ){ $first = true; foreach ( $files as … Read more
I think I found the most semantic solution: If I want to relate a given row of data to “nowhere”, NULL is the best value to reflect that. And it even works with constraints on the field!
It depends on how are you importing those posts. You can use wp_insert_post() with import_id: $postToBeInserted = array( ‘post_title’ => ‘Your Post Title’, ‘post_content’ => ‘Your post content…’, ‘import_id’ => 154 ); wp_insert_post($postToBeInserted); If there is no post with the specified import_id the post will have that ID. That way you won’t have to deal … Read more
I ended up with this <?php //get children of page 241 and display with custom fields $args=array( ‘post_parent’ => 825, ‘post_type’ => ‘page’, ); $my_query = null; $my_query = new WP_Query($args); if( $my_query->have_posts() ) { while ($my_query->have_posts()) : $my_query->the_post(); ?> <?php $img = wp_get_attachment_image_src( get_post_meta($post->ID, ‘product_logo’, true)); ?> <?php $alt_text_for_logo = get_post_meta($post->ID, ‘alt_text_for_logo’, true); ?> … Read more
Try this function wp_get_post_categories() Check more reference from here: https://developer.wordpress.org/reference/functions/wp_get_post_categories/
Quick shot: $countries = get_pages(array( “hierarchical” => 0, “sort_column” => “menu_order”, “sort_order” => “desc”, “meta_key” => “page_type”, “meta_value” => 2, )); $page_ids = array(); foreach ( $countries as $country ) { $page_ids[] = $country->ID; }
While clicking ADD-NEW (i mean when creating new post), it has already assigned an ID. You can catch it using javascript,like: if(document.getElementById(“postID”)){ alert(document.getElementById(“postID”)); } or catch it using PHP: var_dump($GLOBALS); and see the variable name
Here’s a simple example that redirects to the edit posts screen. Since what you’re asking for is how to get the post, I’m not bothering with messages or particular redirect pages or other variables – though note that wp_die() will just kill the page. In my tests, it just gets you a blank one. Anyway, … Read more
If you have the arguments, you can use the_widget() to output the same widget you are searching. If you don’t have the arguments or they change in someway(they could be grabbed from the database though) you would need to iterate all widget areas and all widgets inside each one to match the ID of the … Read more