Tag Info

New answers tagged

0

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' );


0

Do not use query_posts, and for that matter any custom query to replace the main query. It is always problematic and it creates more problems that solving it. Use the main query and make use of pre_get_posts to alter the main query as needed. To solve your issue, remove the query_posts line, this is how author.php should look. <?php ...


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


0

I'd recommend using the template_include filter as opposed to template_redirect, as using this hook means that you don't redirect the user but rather just present them with the template that is requierd. add_filter('template_include', 'my_custom_template_redirect', 99); function my_custom_template_redirect($template){ global $post; if(is_single() ...


0

I would suggest you to have a look on wordpress ajax calls. you could add your ajax like that: add_action( 'wp_ajax_{nopriv_}new_customer', 'my_function_to_hendle_ajax' ); where {nopriv_} is for not logged in users and your function would be like: function my_function_to_hendle_ajax() { $address_line_1 = $_POST['address_line_1']; $address_line_2 ...


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


0

I'd recommend at least two things: Change the priority for your products_create_taxonomies action to at least 1, if not 5 or higher. (I'm thinking 0 is not valid for action priorities for some reason) Add your post type creation into an init action just like you did your taxonomies at an earlier priority than your taxonomy (since you are connecting them ...


0

Yes it is possible. One part of my question is answered here and full code I will type here. I have larger function wich checkes post taxanomy (in this case custom categories for custom post type). Then we check is there particular taxonomy and we change URL structure. add_filter('post_type_link', 'replace_link', 1, 3); function replace_link( $link, $post ...


0

Sounds like you're looking for the NOT IN value of the operator argument of a tax_query. Depending on your situation, you should use either WP_Query or pre_get_posts. Your tax_query would then look something like this: 'tax_query' => array( array( 'taxonomy' => '{your taxonomy slug}', 'field' => 'slug', 'terms' => ...


0

The easiest solution is to use jQuery. Add the below code to any JS file that you include in the admin area. As you haven't given very much information above I don't know a couple of things, so you'll need to amend this example slightly - Change your-post-type to the slug of the post type for which this metabox exists. If it's the default Post then it'll ...


0

My custom post type had has_archive set to true. I tried creating a custom template but due to WordPress hierarchy it was looking for an archive page. I solved my issue by setting has_archive to false and creating a custom template called page-template-projects.php. (the name isn't important) I was then able to setup a page called Projects and use my custom ...


0

i dont see the problam in using WP_Query... it has an author parameter. $cuser_id = get_current_user_id(); $args = array( 'post_type' => 'campaigns', 'posts_per_page' => 100, 'author' => $cuser_id, ); $the_query = new WP_Query($args); if ($the_query->have_posts()) { while ($the_query->have_posts()) ...


0

Here's what I ending up using thanks to Milo, the Codex and this post from http://simple2kx.com/. add_action( 'manage_issues_pm_posts_custom_column', 'my_manage_issues_pm_columns', 10, 2 ); function my_manage_issues_pm_columns( $column, $post_id ) { global $post; switch( $column ) { /* If displaying the 'issues_type' column. */ case 'issues_type' : ...


0

save_post is an action triggered whenever a post or page is created or updated, which could be from an import, post/page edit form, xmlrpc, or post by email. The data for the post is stored in $_POST, $_GET or the global $post_data, depending on how the post was edited. For example, quick edits use $_POST. Since this action is triggered right after the post ...


0

So awkwardly realised I'd been going about this whole thing in a stupid roundabout way and in fact Milo above in the comments is completely right, and proves that the codex still has secrets for everyone, or maybe just me. The eureka (or durr-eka) moment came after reading this post here about setting up and editing the content of the metaboxes. Instead of ...


0

Ok, so I'm feeling generous and will add another answer :) This code will run every time a post is created or updated, and it will add a term to your teacher taxonomy with a name that is the same as the post title. add_action('save_post', 'my_create_teacher_term_from_post'); function my_project_updated_send_email($post_id){ /** Ensure that this is not ...


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

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(); });


0

There's another great article here. They walk you through the 4-step process that they used to set it up.


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');


0

There's actually some cool filters that allow you to pre-populate the title field and editor field, the one we need is default_title. Once in the hook, we need to get our user and display the name: function post_author_title( $post_title, $post ) { if( $post->post_type == 'your_post_type' ) { $user = wp_get_current_user(); ...


0

You have a couple of issues here looking at your code and tags used to tag your question show_posts is wrong. It is depreciated in favor of posts_per_page. Also, it should be showposts. You cannot use showposts and posts_per_page together. You should only use posts_per_page Don't use camelcase in you custom post type names, they are really problematic when ...


0

I'd suggest that you take a look at the Posts 2 Posts plugin. This plugin allows you to create a link between posts of any type. For example - p2p_register_connection_type(array( 'name' => 'courses_to_teachers', 'from' => 'course', 'to' => 'teacher' )); You'll then have an additional box when editing a post of either type - ...


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] ) ) { ...


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


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


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


0

I would suggest an export/import procedure using a tool such as WP CSV. https://wordpress.org/plugins/wp-csv/ We use this plugin quite a bit for importing non-WP data and it's very reliable. Register your CPT (via your plugin or theme functions) Create at least one post in your CPT Export with WP CSV to use as an import template Export your 1458 ...


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

You will need to set the third parameter of wp_register_script(), which is the dependency parameter, $deps. In your code, this is currently set to false, which should actually just be left out or set to an empty array, array() if not needed. In your case, you will set this with the handle of the script you would wish to make it depended on. You can add more ...


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

Ive run into things similar from time to time. What I've ended up doing when using custom post types and taxonomies is the following: Setup a callback on init (before 10) to register taxonomies. Setup another on init (before 10) to register post types. Setup another on 10 to relate them, maybe later if working with other peoples custom taxonomies and post ...


0

in your post loop. use this code. <?php while (have_posts()) : the_post(); $post_type = get_post_type(get_the_ID()); if($post_type !='post'){ get_template_part('content-' . $post_type, get_post_format()); } else { get_template_part( 'content', get_post_format() ); ...


1

EDIT I get the idea that I might have misread your question Just a few notes here If archive-projects.php is a page template, rename it. You should not use archive as a prefix for a page template, or for that matter any other reserved template name. Page templates should be named page-{$name}.php or any other name with prefixes used by the template ...


1

I solved it. SOLUTION: <?php if ( has_term( 'downloads', 'listen', $post->ID ) ) { get_template_part( 'templates/content-downloads-vergriffener-baende' ); } elseif ( has_term( 'untersuchungen', 'listen', $post->ID ) ) { get_template_part( 'templates/content-untersuchungen' ); } elseif ( has_term( 'studien-materialien', 'listen', ...


0

I'd suggest a theme customization. On wp-admin, save the artist's email on a custom field, maybe 'artist-email'. Next add a form on the single-artist.php to send the message, sender name and sender email. Still on the form, add the artist $post->ID as artist-id and contact_artist as action, both as hidden inputs. Use ...


0

Make sure that the Custom Post Type is public. Then create a page with the same name (slug). That shall do. To customize them make sure the CPT has an archive, then create archive templates such as archive-press.php, archive-speaking.php.


-1

Why not just use categories? Everything posted under the category "Speaking" goes to domain.com/speaking if you set the permalinks right :)


0

First, you should change your input field names to something unique. category is a WordPress query var, so submitting a form with that field name may have unexpected results. That said, post_category is only for the category taxonomy, custom taxonomies should use the tax_input parameter. however... if this form is being submitted by users who are not ...


0

I guess you have 4 different news, you want display first news use large image of each page and the news of large image is different others, right? If you right, the following code, maybe work for you. <?php $b=1; $args = array( 'tax_query' => array( array( 'taxonomy' => 'gens', 'field' => 'slug', ...


0

I don't know why have you put $b%4==1 condition. You can simply check for $b==1.And one more thing I would suggest is to use if and else both.So code would be something like this: <?php $b=1; $args = array( 'tax_query' => array( array( 'taxonomy' => 'gens', 'field' => 'slug', ...


1

Does this work? global $post; // make sure the post object is available $slug = $post->post_name; // get the slug // insert the slug into your query $args = array( 'post_type' => 'client_prop', 'posts_per_page' => 10, 'tax_query' => array( array( 'taxonomy' => 'prop_neighborhood', 'field' => 'slug', 'terms' => ...


0

The way you create a template for a specific term is by a file, called taxonomy-$taxonomyname-$slug_of_the_term.php In your case it would look like this: taxonomy-schools-highschool.php Use this image as a guide for any other specific case that you might have: http://codex.wordpress.org/images/9/96/wp-template-hierarchy.jpg


0

The wp action hook fires pretty early, before the $post object is set. I would suggest using the appropriate hook wp_enqueue_scripts instead, and amending your code to: function profolio_localize_script () { if ( is_singular( 'my-gallery' ) ) { $layoutType = get_post_meta( get_queried_object_id(), 'gallery_layout', true ); // Rest of ...


0

add_filter( 'posts_where' , 'posts_where', 10, 2); function posts_where( $where, $query ) { global $wpdb,$wp_query; if ($query->query_vars['post_type'] == 'property') { $where .= ' AND latitude.meta_key="wp_gp_latitude" '; $where .= ' AND longitude.meta_key="wp_gp_longitude" '; } return $where; } If you add $priority = ...


0

The quick and simple method might be to create a custom page template and have the search form send the user to the page that you create with it. <?php /* Template Name: Location Results */ if ( isset($_REQUEST['search_field_name']) && !empty($_REQUEST['search_field_name']) ) { # Read and escape the input data # Do your query, grab your ...


0

I figured it out. For anyone who needs to find this solution I edited the above code. I changed: 'order' => 'DESC' to 'order' => 'ASC' , and 'orderby' => 'meta_value_num' to 'orderby' => 'meta_value' to achieve the order I wanted.


1

First off, I'd like to note a few things wrong with your Post Type and Taxonomy set up. There's a few settings in your $labels that don't make sense: $labels = array( ... 'post_type' => 'attachment', 'post_parent' => $post->ID, 'post_status' => 'inherit', 'post_mime_type' => 'image', ); These last 4 options ...


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_' . ...


0

After registering a custom post type, you must flush the rewrite rules so Wordpress knows what the URL / slug should be. flush_rewrite_rules()



Top 50 recent answers are included