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

sort Posts by custom user filed

So, if you want to display only posts on your homepage, which interests the logged in user, you can use the pre_get_posts-Action: add_action( ‘pre_get_posts’, ‘wp123234_user_specific_loop’ ); function wp123234_user_specific_loop( $query ){ if( ! is_user_logged_in() ) //Just return, if the user is not logged in. return; if( ! $query->is_main_query() ) //If its not the main query return … 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