Subcategory IDs in relation to parent category ID switch case

Ok. This code: $cat_id_gum=””; if(($category[0]->parent)!=’0′) { $cat_id_gum=$category[0]->cat_ID; } elseif(($category[1]->parent)!=’0′) { $cat_id_gum=$category[1]->cat_ID; } elseif(($category[2]->parent)!=’0′) { $cat_id_gum=$category[2]->cat_ID; } else { $cat_id_gum=$category[3]->cat_ID; } Is not really necessary. I’ll show you what I mean in a bit. Later, however, you then set $cat_id_gum to the current post ID… $cat_id_gum = get_the_ID(); … which doesn’t make any sense and makes … Read more

Retrieve ONLY mp3s and set a variable for use in a playlist called by single.php template?

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

Surrogate ID for posts, is there an alternative field in the posts table?

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

List sub pages with custom field content converting image ID to URL

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

Only get post_id [duplicate]

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; }

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)