Tag Info

New answers tagged

0

I achieved this recently with the following code in archive.php add_action('genesis_loop', 'blah_search_results'); function blah_search_results() { while (have_posts()) : the_post(); if (is_category('in-the-news')) { // Get article URL $article_url = get_field('original_article_url'); // rest of theme goes here } endwhile; }


0

I was doing something similar the other day and simply could not get attachment_fields_to_save to work no matter what I tried. I ended up using the edit_attachment filter instead along with code like the following: public function action_edit_attachment( $attachment_id ) { # Check to make sure we were sent by the side of the media editor, not by the ...


0

Credits to Chandan Chaudhary https://gist.github.com/ckchaudhary/8629242#file-get-youtube-video-id-from-url Add the following to the functions.php file. function extractUTubeVidId($url){ /* * type1: http://www.youtube.com/watch?v=9Jr6OtgiOIw * type2: http://www.youtube.com/watch?v=9Jr6OtgiOIw&feature=related * type3: ...


0

An alternative would be to use WordPress's build in auto embed, the following line in core is responsible for auto embed: add_filter( 'the_content', array(&$this, 'autoembed'), 8 ); Which means: Whenever we are about to display content try to auto embed all url's with a priority of 8. You could add a custom filter before this one to add the youtube ...


0

If you have any, even basic experience with PHP, this can be rather straight forward to setup. Have a look at explode and substr. <?php // explode() will split the string up into an array, for ex: $youtube_url = 'https://www.youtube.com/watch?v=dQw4w9WgXcQ'; $youtube_array = explode('?v=', $youtube_url); // we used '?v=' as the delimter, so ...


0

I found that the previous answer, as stated in the comments, only works when saving an existing post and not new posts. The below will work for new posts and existing posts. // func that is going to set our title of our customer magically function w2w_customers_set_title( $data , $postarr ) { // We only care if it's our customer if( $data[ ...


0

If you want something to behave like a "normal" wordpress author then the best thing to do is to create a "dummy" account for it, and if you really want disable the possibility to login to it. For any other solution that mimics the functionality in other ways you first need to fully understand the functionality you are trying to mimic, and by your own words ...


0

Unfortunately this is not possible, there just isn't a hook to use in wp-admin/edit-use.php. The closest you can come is to place something under Personal Options, although this hook is called at the end of that section so this will show your message a little way down the page - add_action('personal_options', 'my_edit_user_admin_message'); function ...


0

single.php //post views -=================================================================================<br> <br> <script type="text/javascript"> <br> // get post views <br> (function($) { <br> function mostViews() { <br> $.getJSON("<?php bloginfo('template_directory'); ...


0

single.php // ------------Post views---------- <script type="text/javascript"> // get post views (function($) { function mostViews() { $.getJSON("<?php bloginfo('template_directory'); ?>/ajax.php", { action: 'get_mostViewedPost', postid: ...


0

You should import the schools as a table in the database, separate from the other WordPress tables. You can than write a function that selects and returns schools and eventually link it to the field via ajax using something like select2 or jquery autocomplete.


0

Assuming you want to do this for all posts that have the custom_field not empty, add this to your functions.php: add_shortcode('update-posts-from-custom-fields', 'upfc_fields321'); function upfc_fields321() { $args = array( 'meta_key' => 'custom_field', 'meta_query' => array( array( 'key' => ...


0

The best way to add extra fields to the wordpress user registration form that I know of is to use the related registration form filters: register_form - This is used to add your fields to the registration form registration_errors - This is used to validate your fields user_register - This is used to add your custom user_meta data to the system and maybe ...


3

I wonder if you want to modify the HTML of the inserted image, with the image_send_to_editor or get_image_tag filters? If that's the case, then here's one example: /** * Add the data-ext-link-title and data-ext-link-url attributes to inserted images. */ add_filter( 'image_send_to_editor', function( $html, $id, $caption, $title, $align, $url, ...


1

@Musa how can we put multiple order value for the fields? I was wondering the same question and I found this : In 4.0, you can now pass an array to WP_Query as the value for orderby. The syntax looks like: $q = new WP_Query( array( 'orderby' => array( 'title' => 'DESC', 'menu_order' => 'ASC' ) ) ); Have a look where for more details : ...


0

I suggest a hierarchical custom post type and a conditional to create an additional loop on your single-{cpt}.php. By using hierarchical custom post type, you can create a sub-cpt , like a sub page as the stats part of it's parent post. The sub-cpt then can be used to store additional data (e.g. in post_content or custom_fields) and also the comment ...


1

You can make use of get_post to get the post objects of a given post. This will be unfiltered objects, so you would want to make use of apply_filters and the appropriate filters described in the linked page. If you need to get info from a custom field, whether native custom fields of ACF fields, you can simply add the ID to the get_post_meta for native ...


1

You can use categories with pages by registering the category taxonomy for the page object type: function categories_for_pages(){ register_taxonomy_for_object_type( 'category', 'page' ); } add_action( 'init', 'categories_for_pages' ); If you want to use a separate taxonomy for this, you can register your own taxonomy for pages.


0

Problem solved, I've used this: $d=new WP_Query( array( 'category__in' => array(4), 'post_type' => 'post', 'posts_per_page' => '-1', 'orderby' => 'meta_value', 'order' => 'ASC', 'meta_query' => array( 'relation' => 'AND', array( 'key' => ...


1

If you'r using ACF plugin you should look the documentation first, here's relevant ACF saves taxonomies terms meta to options table, and they can be accesed using get_field( "{$field_key}", "{$term->taxonomy}_{$term->term_id}" ); So in you'r example it would be: $image = get_field( 'featured_image', 'product-category_' . ...


1

You should be able to query ACF fields in the same way you query normal custom fields. With that in mind, you can do a simple meta_query to get a list of posts from the selected field You can try the following: $args = array( 'post_type' => 'products', 'meta_query' => array( array( 'key' => 'stock', ...


1

Custom fields are also known as post meta. Many things are stored as post meta, such as the ID of the featured image. You'll have noticed that these do not show up in the custom fields section of your posts. This is because these post meta values have keys beginning with an underscore. Similarly any post meta you set that also has an underscore at the ...


0

The custom fields I am using are from the plugin ACF (Advanced Custom Fields). I finally looked at the ACF website, which I should have done originally, and found the function get_field can specify a post so here is the working code: $posts = get_posts(array( 'numberposts' => -1, 'post_type' => 'post',)); foreach($posts as $post) { $arr = ...


0

Thanks to WordPress 4.1 you can do better for meta_query : https://make.wordpress.org/core/2014/10/20/update-on-query-improvements-in-4-1/ function recherche_avancee( $query ) { if ( !is_admin() && $query->is_search ) { $meta_query = array( 'relation' => 'OR' array( 'relation' => 'OR', ...


0

You can add a posts_orderby filter to flip the meta_value: function wpse174075_posts_orderby( $orderby, $query ) { if ( $query->get( 'orderby' ) != 'ddmmyy_date_format' ) return $orderby; if ( ! ( $order = $query->get( 'order' ) ) ) $order = 'DESC'; global $wpdb; $mv = $wpdb->postmeta . '.meta_value'; // Note SUBSTR() position ...


0

For multiple category handling you need either category__in or a tax_query, for multiple custom fields you use meta_query. The various options for both of these are covered in the WP_Query codex page. $args = array( 'posts_per_page' => 10, 'category__in' => array( 163, 165 ), 'meta_query' => array( array( 'key' => ...


0

For posting images you should use the wordpress function media_handle_upload <?php if (isset($_FILES['text-two'])) require_once(ABSPATH . "wp-admin" . '/includes/image.php'); require_once(ABSPATH . "wp-admin" . '/includes/file.php'); require_once(ABSPATH . "wp-admin" . '/includes/media.php'); $attach_id = media_handle_upload( $_FILES['text-two'], ...


2

post is not a valid value for orderby parameter neither DESC. You can choose any of these values. Also, you should stop using query_post. <?php $args = array( 'post_type' => 'ranking', 'orderby' => 'menu_order', 'order' => 'DESC', ...


2

Try using 'NOT EXISTS' instead of 'NOT LIKE' and remove the value ( it'll be removed by WP with NOT EXISTS ): $args = array( 'post_type' => 'post', 'posts_per_page' => 5, 'meta_query' => array( array( 'key' => 'verified', 'compare' => 'NOT EXISTS' ) ) ); $query = new WP_Query( $args ...


0

Save value in database like : 'enddate' => date('Y-m-d'); Generate meta query like : A. Condition : $conArr[0] = array ( 'key'=> 'enddate', 'value' => date('Y-m-d'), 'compare' => '>=', ); B. Query: $args = array( 'meta_query'=>$conArr , 'post_type'=>'tournament', 'orderby' => 'meta_value_num', ) ...



Top 50 recent answers are included