Add custom fields when specific templates are selected

Can you do that? Absolutely! You simply need to query the _wp_page_template meta key value of the $post object, and act accordingly. Perhaps something like so: // Globalize $post global $post; // Get the page template post meta $page_template = get_post_meta( $post->ID, ‘_wp_page_template’, true ); // If the current page uses our specific // template, … Read more

Search that will look in custom field, post title and post content

First, don’t use query_posts. Second, you can pass an s parameter to get most of the way there. $program_search=”test”; $args = array( ‘post_type’ => ‘program’, ‘s’ => $program_search, ‘meta_query’ => array( array( ‘key’ => ‘keywords’, ‘value’ => $program_search, ‘compare’ => ‘LIKE’ ), ) ); $t = new WP_Query($args); var_dump($t->request); That s parameter kicks the ordinary … Read more

Using get_posts with arguments found in meta keys

get_posts accepts any of the arguments that WP_Query accepts. So there’s a few options. 1. meta_key and meta_value <?php get_posts(array( // some more args here ‘meta_key’ => ‘some_key’, ‘meta_value’ => ‘some value’ )); 2. meta_query meta_query is more sophisticated that using meta_key and meta_value. For instance, say you wanted to get posts that have the … Read more

How to automatically apply woocommerce product title to all product images alt tags?

This is what you need, taken from – https://stackoverflow.com/questions/27087772/how-can-i-change-meta-alt-and-title-in-catalog-thumbnail-product-thumbnail add_filter(‘wp_get_attachment_image_attributes’, ‘change_attachement_image_attributes’, 20, 2); function change_attachement_image_attributes( $attr, $attachment ){ // Get post parent $parent = get_post_field( ‘post_parent’, $attachment); // Get post type to check if it’s product $type = get_post_field( ‘post_type’, $parent); if( $type != ‘product’ ){ return $attr; } /// Get title $title = get_post_field( … Read more

how to filter by last name for custom post

Order by the last word in the post title To order by the speaker’s last name, you can use the following setup (PHP 5.4+): // args $args = [ ‘posts_per_page’ => 10, ‘post_type’ => ‘speaker’, ‘meta_key’ => ‘speaker-front-page’, ‘meta_value’ => ‘1’, ‘orderby’ => ‘wpse_last_word’, //<– Our custom ordering! ‘order’ => ‘ASC’ ]; // query $the_query … Read more

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