Always Encounter Using ID in WordPress as a Final Solution [closed]

You’re absolutely correct that hard-coding specific IDs is a bad idea. IDs are very much subject to change, and normal activity through the UI can cause problems with any code expecting a specific ID, which makes them fragile. However, when you see solutions involving a specific ID, you need to keep in mind that the … Read more

Categories id Tags

How to add ID attribute to each submenu?

In your Walker_N_Menu class’s start_lvl() method, you’re setting the <ul>‘s id to submenu1. You can change this (using, in this example, the $depth parameter passed to start_lvl()) to be unique: function start_lvl( &$output, $depth = 0, $args = array() ) { // Depth-dependent classes. $indent = ( $depth > 0 ? str_repeat( “\t”, $depth ) … Read more

current post with current author

A compacted version that does not load the globals yet calls upon them directly. if( is_user_logged_in() and // Force user validation… STUFF !empty($GLOBALS[‘post’]) and // Check if a $post exists in globals !empty($GLOBALS[‘current_user’]) and // Check if current_user exists in globals ($GLOBALS[‘current_user’]->ID == $GLOBALS[‘post’]->post_author) // Match User IDs ){ // This is your Author speaking, … Read more

Getting the ID of any image for use in functions.php

Hopefully this helps, function mat_image_credit() { global $post; $args = array( ‘post_type’ => ‘attachment’, ‘post_parent’ => $post->ID, ‘post_mime_type’ => ‘image’, ‘numberposts’ => -1, ); $imgs = get_posts($args); foreach ($imgs as $img) { $field1 = slt_cf_field_value(‘flickr_credit’, ‘attachment’, $img->ID); $field2 = slt_cf_field_value(‘custom_credit’, ‘attachment’, $img->ID); if (!empty ( $field1 ) ) { echo ‘Image by ‘ . $field1; … Read more

Why is my Blog Page ID == First Post ID?

the ‘posts page’ ID when using a static front page and a different posts page is: get_option( ‘page_for_posts’ ) in some context: if( is_home() && get_option( ‘page_for_posts’ ) ) { $page_ID = get_option( ‘page_for_posts’ ); }

Post-ID in url differs from $post->ID

There are two ways to get what you need. One is mentioned in Identify the page being shown while in The Loop: $post_id = get_queried_object_id(); Unfortunately, this might break. get_queried_object_id() looks in the global variable $wp_query for the ID, and that variable can be overwritten during the page rendering by query_posts(). The same is true … Read more

getting parent page id when using custom menu.

Not sure if this is robust enough, but it shows basic traversal through menu to look for current post first then for its menu parent: /** * @param mixed $menu * @param int $post_id * * @return WP_Post|bool */ function get_menu_parent( $menu, $post_id = null ) { $post_id = $post_id ? : get_the_ID(); $menu_items = … Read more

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