Articles of id

Shortcode for a link and thumbnail

<?php // Add Shortcode function blog_shortcode( $atts ) { // Attributes extract( shortcode_atts( array( ‘id’ => ”, ), $atts ) ); // Code if (has_post_thumbnail()) { $url = wp_get_attachment_url( get_post_thumbnail_id( $id ) ); } if ( isset( $id ) ) { return ‘<img src=”‘ . $url . ‘”/><a href=”‘ . get_permalink( $id ) . ‘”>’ […]

Transient unique names

What would be the correct way to assign a different name to each transient for each instance of a plugin used as a widget or shortcode?

Add id to menu items in wp_nav_menu

I’m using wp_nav_menu in WordPress to create my navigation The output is similar to this(I have removed href links) <nav id=”pageNav”> <ul id=”menu-headernav” class=”menu”> <li><a href=””>Home</a></li> <li><a href=””>About</a></li> <li><a href=””>Services</a></li> <li><a href=””>Work</a></li> <li><a href=””>Contact</a></li> </ul> </nav> I need to style each link separately. How can I add an id to each (li) or (a) in […]

Get a post_id where meta_value equals something in a serialized meta_value field

I’m storing CPT products‘ post IDs into CPT companies‘ post meta (meta_key = prefix_products). As a company can have multiple products, so I’m storing them into a PHP serialized array value. s:48:”a:3:{i:0;s:3:”334″;i:1;s:3:”333″;i:2;s:3:”331″;}”; Where 334, 333, 331 are three post_ids of post type products. I need to get the post_id of the CPT companies where the […]

How to get home page ID?

I’m building a WordPress plugin in which I need to get the HOME page ID value. Do you know how can I get it? I know that we can get the current ID with the_ID() or get_the_ID() function, but I need specificly the HOME page ID value. My plugin is located at the following directory […]

Getting current post ID in functions.php

I need to get the current post ID into an array in my functions.php. function filter_query( $query ) { $query[‘post__not_in’] = array(7); return $query; } add_filter(‘wpc_query’, ‘filter_query’, 1 ); get_the_ID(); or global $post; $id = $post->ID; didn’t work for some reasons.

How to check the array of featured images IDs

I’m trying to show some specific text on top of the featured images depending on their IDs. Some of the featured images will have the same text. $post_thumbnail_id = get_post_thumbnail_id(); if($post_thumbnail_id ==’2030′) { echo ‘<span>Location</span>’; } How do I check the array of $post_thumbnail_id? The following example does not work. if($post_thumbnail_id == array(‘1000′,’2000’))

get author comment id by comment id

I need to get author ID by comment ID Example functionName($commentID){ return $authorID; }

get the_title_attribute by id

I’m creating a list with a few permalinks which I call to with <a href=”<?php echo get_permalink($id); ?>” title=”…. And for the title I want to call the_title_attribute(). But it seems it can only be called within a loop, and not by id. How do I correctly get a title attribute? Note: The reason I […]

Is there a better, more efficient way to get the post id outside the loop?

Right now I am using: $wp_query->post->ID; I want to know if there is a better way for getting the post id that consumes less resources?