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

ID of Front-Page

This should do the trick. global $wp_query; $post = $wp_query->get_queried_object(); $post->ID; This’ll give you the ID for each page you’re on. get_option( ‘page_on_front’ ) should’ve worked though.

Get post or page id early

For mee it seems that the template_redirect hook worked. Thanks to Pieter Goosen. Heres a solution that should work on earlier hooks: function gdymc_object_exists( $object_id ) { return ( get_the_title( $object_id ) ) ? true : false; } function gdymc_objectID() { if( is_numeric( $_GET[‘page_id’] ) ): $object_id = $_GET[‘page_id’]; elseif( is_numeric( $_GET[‘p’] ) ): $object_id … Read more

pass user id in slug and get user information

The code seems incomplete. Maybe the problem is simply that you define $id but then try to use $user_id? Also, I think id is a protected variable, so maybe use my_id instead. Try this: www.mysite.com/test?my_id=123 $user_id = $_REQUEST[‘my_id’]; $camp_link = get_site_url().”/campaign-detail/?id=”.$user_id; echo “<p class=”campaign_store_name”><a href=””.$camp_link.””>”.$camp_title.”</a></p>”; $arform_id = Get_ARFORM_ID_using_slug($camp_link);