Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

post-meta

Using Form to alter PHP variable [closed]

Don’t put your variables in single quotes. This: if(isset($submit)){ $args = array( ‘numberposts’ => 10, ‘meta_key’ => ‘$filter’, ‘orderby’ => ‘meta_value’, ‘order’ => ‘DESC’, ‘post_type’ => ‘things’, ‘post_status’ => ‘publish’ ); $mystuff = get_posts( $args ); $name = $filter ; } Should be this: if(isset($submit)){ $args = array( ‘numberposts’ => 10, ‘meta_key’ => $filter, ‘orderby’ … Read more

Categories post-meta Tags forms, post-meta, variables

Limiting the amount of posts this displays

You have posts_per_page = -1, which means show unlimited posts. Change the -1 to the number of posts you want to appear. Also you have output that skips if your “next_open_day” meta value is null, but the query will only run 3 times, so you need to move that logic into the query itself by … Read more

Categories query-posts Tags post-meta, query-posts

Problem with get_post_meta

I was having some issues like yours. It was because it was on a page template with a query above it. All I had to do was reset the query.

Categories post-meta Tags post-meta

query with custom field

A quick google search would have directed you to this page: http://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters

Categories post-meta Tags post-meta

Order by a meta field in query loop

<?php $cat = get_post_meta( get_the_ID(), ‘cat_page’, true ); $args = array( ‘category_name’ => $cat, ‘meta_key’ => ‘niveau_chiffre’, ‘orderby’ => ‘meta_value_num’, //Since we’re dealing with numbers ‘order’ => ‘ASC’, //’meta_query’ => array( // array( //’key’ => ‘niveau-chiffre’, //’value’ => ‘niveau-chiffre’, Don’t give a value because we’re not looking for a specific one //’compare’ => ‘>=’, We’re … Read more

Categories custom-field Tags custom-field, loop, post-meta, sort

add multiple values (array) to post meta_input

You can simply store the meta as an array… Also to hell with add_post_meta… I never use it. update defaults to add if the meta doesn’t exist for the post. update_post_meta($post_id, “_event_musikstil”, $event_musikstil); wordpress will store the value as a serialized array then so just retrieve it like get_post_meta($post_id, “_event_musikstil”, TRUE); Hope this helps. Another … Read more

Categories custom-field Tags custom-field, post-meta, wp-insert-post

custom field with links

Lets go with an example… Custom Field Name: buy-ticket Custom Field Value: http://example.com/link-to-ticket/ And you said, you want a button called “Buy ticket” linking to the Custom Field Value. This how you do it: <a href=”https://wordpress.stackexchange.com/questions/57443/<?php echo get_post_meta($post->ID,”buy-ticket’, true); ?>” title=”Buy a ticket right away!”> <span>Button text or code here</span> </a> SOURCE: WordPress Codex Function … Read more

Categories custom-field Tags custom-field, post-meta

Display a list of posts whose meta field values are equal to the ID of the post being viewed?

For the author single page $query = new WP_Query(array( ‘post_type’ => ‘books’, ‘meta_key’ => ‘author’, ‘meta_value’ => get_the_ID() // assuming you’re inside the loop )); while($query->have_posts()) { $query->the_post(); the_title(); } wp_reset_query(); For the books archive page // assuming you’re inside the loop $author = get_post(get_post_meta(get_the_ID(), ‘author’, true));

Categories custom-post-types Tags custom-field, custom-post-types, meta-value, post-meta

get posts based on category and post meta

Possible Problems: A change in the time zone could between ‘End_Time’ and date( ‘G:i’ ). A change in the time between calling date( ‘G:i’ ) and date( ‘w’ ). Repeated use of the date( ‘w’ ) function. A meta query logic problem. Any of these could be the culprit. The time zone problem If the … Read more

Categories get-posts Tags date-time, get-posts, post-meta

Display post’s description and caption

Something like this should get you close (untested): <?php foreach($my_posts as $post){ $thisPostId = $post->ID; $thisPost = $get_post($thisPostId); $thisPostTitle = apply_filters(‘the_title’, $thisPost->post_title); $thisPostThumbnail = get_the_post_thumbnail($thisPost); $thisPostContent = apply_filters(‘the_excerpt’, $thisPost->post_excerpt); $data[] = array( “id” => $thisPost, “title” => $thisPostTitle, “image” => $thisPostThumbnail, “content” => $thisPostContent ); } ?>

Categories get-posts Tags get-posts, post-content, post-meta
Older posts
Newer posts
← Previous Page1 … Page9 Page10 Page11 … Page204 Next →
+ More

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Post Navigation Elementor
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • WPFacet multiple loop displaying duplicate content
  • Get the name of the template/*html file used
  • Fix: WordPress.DB.PreparedSQL.NotPrepared Plugin Check (PCP)
  • Removing unnecessary CSS and JS code from wp_head()
  • hexagonal image gallery. Am I on the right track? [closed]
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
© 2026 Read For Learn
Next Page »
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress