Tag Info

Hot answers tagged

3

Make use of an offset to skip the first 2 posts if you need the third post only, and then set you posts_per_page to 1 to get only that specific post You can try something like this in your arguments $args = array( 'post_type' => 'testimonial', 'offset' => 2, 'posts_per_page' => 1 ); $testimonials = new WP_Query( $args ); while( ...


2

You could use the current_post property and the rewind_posts() method of the WP_Query class, to target the relevant post objects. You could try playing with the following example (untested): if( $testimonials->post_count >= 3 ) { // First post: $nr = 1; if( isset( $testimonials->posts[$nr-1] ) ) { ...


2

Get all custom post types: $post_types = get_post_types( array ( '_builtin' => FALSE ), 'objects' ); Sort them by their name: uasort( $post_types, 'sort_cpts_by_label' ); /** * Sort post types by their display label. * * @param string $cpt1 * @param string $cpt2 * @return int */ function sort_cpts_by_label( $cpt1, $cpt2 ) { return ...


2

The second parameter for get_page_by_title() is $output, with the third being $post_type. This should solve your porblem - $patchwork = get_page_by_title( 'Patchwork 01', OBJECT, 'patchwork' ); echo $patchwork->ID; Please have a look at the Function Reference for get_page_by_title() for more information.


1

If using get_the_terms, you can just do your if loop once for each taxonomy and then join them after the three loops. Of course, it would probably be more efficient to use: wp_get_post_terms( $post_id, $taxonomy, $args ); You could then do something like: wp_get_post_terms( $post_id, array( 'resource_roles', 'resource_media', 'resource_theme' ) ); ...


1

Create your custom post type and then try this. (BACKUP FIRST AS THIS IS UNTESTED). <?php // Get all posts in category "5" $news_posts = get_posts( array( 'category' => 5 ) ); // Loop through them foreach($news_posts as $p): // Update the post type wp_update_post( array( 'ID' => $p->ID, ...


1

Your post_type_link uses the post's ID, but the item query var expects a postname. To query by ID you need to use the p query var and set post_type: add_rewrite_rule('food/([^/]+)/?$','index.php?post_type=item&p=$matches[1]','top');


1

This is a javascript issue in your theme. You're blocking clicks on elements with the classname .class which contains those links in the file express/includes/scripts/scripts.js: $('.class').click(function(e) { e.preventDefault(); });


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 : ...


1

After some research I have found a blog who actually had an answer to this problem. Here is the function along with the blog url. function taxonomy_slug_rewrite($wp_rewrite) { $rules = array(); // get all custom taxonomies $taxonomies = get_taxonomies(array('_builtin' => false), 'objects'); // get all custom post types $post_types = ...


1

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

Hmm, missed this codex page... To solve this the number should be passed as a decimal as a string rather than an int; 20 -> '19.1' adjusted code; add_menu_page( 'Settings', 'Settings', 'manage_options', 'plugin_name', 'plugin_name_options_page', content_url( '/img/icon.png', __FILE__), '19.1' );


1

You can do this in one loop without as custom query. A couple of clever functions should get you there So lets look at a solution. First things first. I would suggest to separate your code completely here for easiness of reading and organisation. Roll back the changes in content.php and use this template only for all other templates. Create a separate ...



Only top voted, non community-wiki answers of a minimum length are eligible