Title: About Optimizing Querying Posts by Custom Fields
Last modified: August 19, 2016

---

# About Optimizing Querying Posts by Custom Fields

 *  Resolved [Muhammad Mahmoud](https://wordpress.org/support/users/hawyphp/)
 * (@hawyphp)
 * [16 years, 3 months ago](https://wordpress.org/support/topic/about-optimizing-querying-posts-by-custom-fields/)
 * Hi all
 * first .. sorry 4 my english 🙂
 * i am web developer and using wordpress as framework for any Customized CMS i 
   want build
 * if i want to make a video Cms for example and want to make keys for videos instead
   of ID’S
 * each video is post has ID , and Customfield ( “vkey” => “1A2B3C” )
 * each post will have the customfield ( “vkey” )
 * so i want to make a custom page to view video by key
 * example.com/vid/ANYKEYHERE
 * will take the key and QueryPost it
 * my question here
    if i will have more than 1,000,000 Videos [ POSTS ]
 * i looked up at (“POSTMETA”) table structure @ wordpress database
    and ofcourse
   they cant make this field (“UNIQUE”) or Indexed coz this field may have alot 
   of similar values like values of key ( _edit_last )
 * so i think the query will look at all (“vkey”) values to find the one matching
   the Key comes from URL
 * i ask about this coz this page will be the most visited page at the cms and we
   will have alot of visits when we lunch it
 * i hope that any body can get what i talk about .. coz i know my bad english 🙁
 * Thanks in Advance

Viewing 5 replies - 1 through 5 (of 5 total)

 *  [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * (@vtxyzzy)
 * [16 years, 3 months ago](https://wordpress.org/support/topic/about-optimizing-querying-posts-by-custom-fields/#post-1384903)
 * One possible solution (but not simple) would be to have your own table containing
   vkey-values and post ID, indexed on vkey-value. Then use hooks to update the 
   table whenever a post is added, updated, or deleted.
 *  Thread Starter [Muhammad Mahmoud](https://wordpress.org/support/users/hawyphp/)
 * (@hawyphp)
 * [16 years, 3 months ago](https://wordpress.org/support/topic/about-optimizing-querying-posts-by-custom-fields/#post-1385135)
 * it’s right
    but is there any simpler solution ?
 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [16 years, 3 months ago](https://wordpress.org/support/topic/about-optimizing-querying-posts-by-custom-fields/#post-1385137)
 * Can’t speak to the performance of that situation, but look at [http://wordpress.org/extend/plugins/custom-field-taxonomies/](http://wordpress.org/extend/plugins/custom-field-taxonomies/)
 * Also see:
    [WordPress_Optimization](http://codex.wordpress.org/WordPress_Optimization)
 *  [scribu](https://wordpress.org/support/users/scribu/)
 * (@scribu)
 * [16 years, 3 months ago](https://wordpress.org/support/topic/about-optimizing-querying-posts-by-custom-fields/#post-1385145)
 * I would add the vkey column to the wp_posts table directly. You can make it unique
   and you avoid a JOIN.
 *  Thread Starter [Muhammad Mahmoud](https://wordpress.org/support/users/hawyphp/)
 * (@hawyphp)
 * [16 years, 3 months ago](https://wordpress.org/support/topic/about-optimizing-querying-posts-by-custom-fields/#post-1385175)
 * [@michaelh](https://wordpress.org/support/users/michaelh/)
 * Thanks for your attention .. but this plug wasnt to get what i mean
 * @ Scribu
 * Thanks for your reply .. it’s similar to vtxyzzy’s idea
 * i asked PHP Web Developer .. his name is Burak Guzel [phpandstuff.com]
 * and he helped me that i can make index(non-unique) to the field with a specific
   length even it’s type is TEXT
 * e.g. i will index the first 20 charachters from this field
    –> alter table wp_postmeta
   ADD INDEX ( `meta_value` ( 20 ) )
 * Thanks 4 All

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘About Optimizing Querying Posts by Custom Fields’ is closed to new replies.

## Tags

 * [custom](https://wordpress.org/support/topic-tag/custom/)
 * [database](https://wordpress.org/support/topic-tag/database/)
 * [field](https://wordpress.org/support/topic-tag/field/)
 * [index](https://wordpress.org/support/topic-tag/index/)
 * [keys](https://wordpress.org/support/topic-tag/keys/)
 * [postmeta](https://wordpress.org/support/topic-tag/postmeta/)

 * 5 replies
 * 4 participants
 * Last reply from: [Muhammad Mahmoud](https://wordpress.org/support/users/hawyphp/)
 * Last activity: [16 years, 3 months ago](https://wordpress.org/support/topic/about-optimizing-querying-posts-by-custom-fields/#post-1385175)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
