Make custom user_meta as permalink for post

After searching a lot i finally came up with this solution. My custom post type is “facility” and the custom_user_meta=”organization_name“. First go to http://localhost/wp-admin/options-permalink.php and choose custom structure – in the text box put /%organization_name%/%postname%/ After that put the below given code in functions.php add_action(‘init’, ‘tdd_add_rewrite_rules2’); function tdd_add_rewrite_rules2(){ // Register custom rewrite rules global $wp_rewrite; … Read more

Query Custom Fields in Searchform

Option 1 – Grab the post ID at the same time You can also select the post_id field when you running your query, allowing you to then get the post with a call to get_post($values->post_id); (if required). global $wpdb; $query = $wpdb->prepare(‘ SELECT p.post_id, p.meta_value FROM %1$s AS p WHERE p.meta_key = “post_views_count”‘, $wpdb->postmeta ); … Read more

Get first URL from custom field, download and set as featured image on post publish

You can access custom fields like that: get_post_meta($post_id, $key, $single); see https://codex.wordpress.org/Custom_Fields you could extent some of the plugins that already solve the rest of your problem like the wp-autoset-featured-image-plus plugin and tell it to use the string from your custom field instead of the post body. the relevant code part should be this line … Read more

Ordering posts by custom fields

This is a code I’m using ina website that I’m creating for a client. Maybe it can point you in the right direction: $current_date = date(‘Y-m-d’); $args = array( ‘post_type’ => ‘billboard_evento’, ‘posts_per_page’ => 4, ‘meta_key’ => ‘fecha-inicio’, //Declaring wich meta key I want to use ‘orderby’ => ‘fecha-inicio’, //Ordering the queried elements by meta … Read more

Custom fields and auto save

You need to check to see whether the $_POST data contains your custom field information before saving it: if (!empty($_POST[“intro”])) { update_post_meta($post->ID, “intro”, $_POST[“intro”]); } Also, WordPress will pass the post ID and post object into your callback if you ask it too. function save_intro($ID, $post){ //preserve the data in the admin section // … … Read more

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