Tag Info

New answers tagged

0

You could try this, IF the current user is logged in AND not Adminstrator it will pull all posts from the current user, otherwise it should default and show all posts from all users. <?php function filter_posts_by_author( $query ) { if( is_user_logged_in() ) { if( !current_user_can( 'administrator' ) ) { global ...


1

I really think that you have over complicated things here. Here is how I would treat the matter First of all, create a custom post type (which you have already done) Assign a custom taxonomy to it Convert all the posts from the listas-2 category to your created custom post type. See this post on how to Re-assign your custom taxonomy to these converted ...


0

Wordpress, by default don't enable comments on custom post types, and once you have added support for comments, you still get the following message: Comments are closed You have to basically manually visit each custom post and enable comments in the post editor screen. There are however a workaround to enable comments by default in bulk. You can use the ...


0

You can't use double sorting option. You can try this code once: add_action( 'pre_get_posts', 'fetch_staff_people' ); function fetch_staff_people( $query ) { if ( is_post_type_archive('staff') && $query->is_main_query() ) { $query->set( 'post_per_page', '-1' ); $query->set( 'meta_key', '_staff_purpose' ); ...


1

I think you forgot to check if $the_query have posts. <?php $args = array( 'post_type' => 'testimonials', 'posts_per_page' => 1, 'orderby' => 'rand' ); $the_query = new WP_Query( $args ); ?> <?php if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ...


0

How are you currently generating the login URL & handling the redirect? You should simply be using wp_loginout and passing the permalink as the redirect, and let WordPress handle everything else: <?php wp_loginout( get_permalink() ) ?> Or for a more custom implementation: <?php if ( ! is_user_logged_in() ) : ?> <a href="<?php ...


0

For serializing and unserializing Data in Wordpress, you can use maybe_unserialize and maybe_serialize. If you want to handle the data and add/change values, you could use something like this: $metaarray = maybe_unserialize(get_post_meta($post_id,'_ait-dir-item',TRUE)); //now $metaarray has an array, if it is serialized. If not, $metaarray has a string. ...


0

You should first run the wp_insert_post() which will return the post ID. Then use that post ID to add your custom fields. Use add_post_meta() to add the custom fields. $post_id = wp_insert_post( $args ); add_post_meta( $post_id, 'longitude', $my_long ); add_post_meta( $post_id, 'latitude', $my_lat );


0

I think the solution is very easy. After registering you post type: register_post_type( 'portfolio', $args ); flush_rewrite_rules(); flush_rewrite_rules will do it for you!


1

You have inserted wrong thumb functions for large fancybox image URLs. <a href="<?php get_the_post_thumbnail(); ?>" class="project-img fancybox"></a> This get_the_post_thumbnail() returns an HTML image element but you need URL of image. Your first code should be like this. <?php $args = array( 'post_type' => 'portfolio' ); $loop = ...


0

If I understand you correctly, you need to show all posts from a term when a term's page is being displayed. Before I answer the real question, there are a few points I would like to highlight since you are new to Wordpress Never use hyphens (-) to separate names in custom post type names and custom taxonomy names. They are extremely troublesome later, ...


1

orderby does not accept the values ASC or DESC. These are acceptable values for the parameter order. Changing 'orderby' => 'rand' to 'order' => 'ASC' should be sufficient and should by rule work As already pointed out, if (have_posts() ): should be if ($the_query->have_posts() ): Apart from that little discrepancy, you code have to work It ...


0

I solved the issue very easy. $type = array('event','post'); $args=array( 'post_type' => $type, 'category' => '8', 'post_status' => 'publish', 'posts_per_page' => 5, 'caller_get_posts'=> 1); These gets all custom posts 'event' and normal posts from category 8. ...


-1

<?php the_post(); // $postType holds all the information of the post type of the current post you are viewing $postType = get_post_type_object(get_post_type()); // $postSlug is the slug you defined in the rewrite column: about/team-members $postSlug = $postType->rewrite['slug']; // $datas = { [0] => 'about', [1] => 'team-members' } $datas = ...


0

A possible solution is whenever the custom post type is saved, you can set its' parent to be about/team-members prgrammatically. Here are the steps: You can use the save_post hook to 'catch' whenever someone tries to save a post. If that post is the custom post type you are after, then proceed. Make sure to set the custom post's parent to the page you ...


0

I had some more time to dig into this myself (sorry if I wasted anyone's time), and I figured that for me, the best way to solve the highlighting problem would be to kinda re-do what _wp_menu_item_classes_by_context() is doing, that is iterate over all parents and ancestors of the menu item that acts as the parent of my custom post type, and add classes ...


0

Disclaimer: After giving it a try this seems a not longer existing problem to me, because - at least for me - it just works on my WP 3.9.2 installation. Couldn't find a according bug tracker though. I have out together a little plugin to test this, which might help someone. But like I said in above disclaimer, I couldn't reproduce the problem in a current ...


0

I personally now use on every project Advanced Custom Fields (http://advancedcustomfields.com/), it is well-maintained, easy to manage, extremely powerful and ever-evolving in terms of features. It has a free and a Pro version (right now the plugin creator is moving towards a new version where there is only Pro, not single Add-Ons). Your repeater field would ...


0

Use this metabox addon in your plugin. It is easy to use and add


1

This may be an alternative for you. The Advanced Custom Fields plug in has an Image Field, which allows images to be uploaded and selected. You can set the field to show on your Custom Post Type pages and also integrate a line of code into your template file. You can create as many image fields as needed. Learn more about the Image field here.


0

i finally figured out a solution. I guess it's not the perfect one, because all posts are still looped and the wrong language just doesn't show, but for now it works. I am still open for ideas. My idea right now is to get the language of the post and don't display it if it doesn't match the pages language. Here's the new part. global $polylang; $postlang ...


0

just changed the query a little $meta_query_args=array( 'relation' => 'AND', array( 'key' => 'event-start-date', 'value' => $date_today, 'compare' => '<', ) ...


1

If you want an example of how to do the dropdown filtering using ajax, then if you factor out your taxonomy dropdown into your "functions.php": function my_dropdown_categories( $taxonomy, $current_selected = '', $include = null ) { // Get all terms of the chosen taxonomy $terms = get_terms($taxonomy, array('orderby' => 'name')); // our ...


0

Use jQuery action on first dropdown .. this is the code from your mentioned url .. You can populate the arrays using php functions ... function dynamic1(parent,child) { var parent_array = new Array(); // This is the default value parent_array[''] = ['Please select a manufacturer']; // All other elements // parent_array['PARENT NAME'] = ...


0

Single pages are designed to display a single post, and not an index of posts as an archive page would. I'm not really sure what are you trying to achieve here as well. It is always a bad idea to try and use a specific template for anything else than what it was intended for. The main query are quite specific to a specific template, in this case, the main ...


2

The correct way to register a taxonomy is to wait for the action registered_post_type, because that’s the only way to know that your post type actually exists. This action is fired when a post type was registered. Core post types are registered twice for reasons. You have to wait for the second call, because the rewrite object is not available earlier. If ...


0

From the register_taxonomy() codex page: Better be safe than sorry when registering custom taxonomies for custom post types. Use register_taxonomy_for_object_type() right after the function to interconnect them. Else you could run into minetraps where the post type isn't attached inside filter callback that run during parse_request or pre_get_posts. ...


0

Try this add_action( 'init', 'tag_synchro', 10 ); It might be the case that, when you set priority to 0 , your callback does not get called.


0

You are looking for function get_term_link. Example $my_term_link = get_term_link($cat_lists); Here $cat_lists is term object. Official Documentation


1

This might not answer your question, but you have a few issues with your code Do not use uppercase letters in function names, taxonomy names and custom post type names. Only use lowercase letters. Separate names with a underscore (_). Also, just a tip, never start these names with letters, or use a hyphen (-) to separate names Never use ...


0

Make the following modifications, I hope it will do the job function AppManager_custom_taxonomy() { $labels = array( 'name' => _x( 'App Categories', 'taxonomy general name' ), 'singular_name' => _x( 'App Category', 'taxonomy singular name' ), 'search_items' => __( 'Search App Categories' ), 'all_items' ...


1

It sounds like all you need to do is specify the 'post_type' argument which is only 'post' by default. $posts = get_posts( array( 'category' => 16, 'post_type' => array( 'post', '{another_post_type}', '{another_post_type}', '{another_post_type}' ) ) ); You might also consider using WP_Query to make a custom loop instead. That's a bit ...


0

I finally found the custom post type data. It is stored in the wp_post table where post_type = custom post type (e.g. "products"). The field (column) data is stored in wp_postmeta where the meta_key is the column name and meta_value is the column value. This query will bring back all data associated with the custom post type "products": SELECT P.ID, ...


0

What you want can be done. It's just not likely to be really clean and neat. You can accomplish this by using a custom Walker Class for the wp_nav_menu() when you insert it. class My_Walker_Class extends Walker_Nav_Menu { function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) { $output .= sprintf( "\n<li><a ...


1

At the end of your code after the last } add : add_action('init,'products_post_type'); Make sure you're adding this to the file in the /wp-content/your_custom_theme/includes/theme-init.php file, and then of course update the permalink. With the CherryFramework, make sure you don't modify any of the files in the CherryFramework folder, or you'll lose out ...


1

Try adding: add_action( 'init', 'products_post_type' ); As you can see in the Codex example for register_post_type() you must add your function to the init hook, so that it is actually run. Otherwise, what you have, is a function that is defined, but never executed. If you did this with a default theme, then you were adding the function to an action ...


0

The problem is that you are passing a comma separated list of terms, not an array of term. For example, if you enter 'army,navy,airforce' in the custom field: $related = array ( get_post_meta($post->ID, 'related_categories', true) ); //$related = array('army,navy,airforce'); //What you need is //$related = array('army','navy,'airforce'); You need to ...


0

You can add all your post types in an array as a variable, and then pass that through a foreach loop $post_types = array('members','post','testimonial'); foreach ($post_types as $type) { if( $post_type == $type ) wp_enqueue_script( 'portfolio-admin-script', plugins_url( '/js/admin.js', __FILE__),'','', true); //"TRUE"-ADDS JS TO FOOTER }


0

You have to use OR(||) operator to test for each of the condition. OR returns true if any of the condition is true if ( ($post_type == 'members') || ($post_type == 'post') || ($post_type == 'testimonial') )


0

Try this: if( in_array($post_type, array( 'members','post','testimonial' ) ) ) wp_enqueue_script( 'portfolio-admin-script', plugins_url( '/js/admin.js', __FILE__),'','', true); } Function in_array is used to check if current post type is in the array of allowed post types.


0

I haven't tested this extensively but it does work on both Publish and Update. When a post is Published or Updated it checks if a parent is set, grabs the parent to get all the parents taxonomies, then loops through and sets the children terms as the parents terms taxonomy by taxonomy. /** Set Child Terms to Parent Terms **/ function set_parent_terms( ...


1

You can create a custom query with WP_Query to get all posts from your post type. This is how a basic query will look like, you just need to tweak it to your needs <?php // The Query $the_query = new WP_Query( 'post_type=project&posts_per_page=-1' ); // The Loop if ( $the_query->have_posts() ) { while ( $the_query->have_posts() ) { ...


0

Your issue is related to your use of feed, which is both a reserved keyword, and an existing URL rewrite. e.g. RSS feeds etc: example.com/feed/rss2 You need to change your rewrite rules to use something other than 'feed' in your URL. The same goes for any taxonomies or post types that try to call themselves 'feed'.


0

I got the answer. Now I have the code function fichasvtmbasicas_meta_box_callback( $post ) { wp_nonce_field( 'fichasvtmbasicas_meta_box', 'fichasvtmbasicas_meta_box_nonce' ); $fichasvtmbasicas_geracao_field = get_post_meta( $post->ID, '_vtmbasica_geracao_value_key', true ); echo '<div class="unidadeelementotopovtm"><label ...


0

$admins = get_role( 'brokers','administrator' ); part doesn't make sense. get_role() only accepts one role name and only ever returns one role. You need to make these changes to the two roles separately.


1

I would look into using HyperDB instead. This would allow you to pull data from several databases while one is replicated as the "master" database. http://wordpress.org/plugins/hyperdb/ From the description page of the plugin: It supports: Read and write servers (replication) Configurable priority for reading and writing Local and remote ...


1

Don't change the main query. You can simply achieve what you want by using pre_get_posts.Fall back to the default loop in category-5.php and add the following to your functions.php function include_category_cpt( $query ) { if ( !is_admin() && $query->is_category( '5' ) && $query->is_main_query() ) { $query->set( ...


3

The problem is this part: wp_get_attachment_image_src($image, 'large')[0] In old PHP versions like 5.3 and below, you cannot reference an entry ([0]) from the returned array of a function. The problem is that WP Engine is still on PHP 5.3, which reached end of life recently and doesn’t get security updates anymore. For the history see PHP 5.3 - Thanks for ...


1

I solved it like that: <?php $type = 'eveniment'; $args=array( 'post_type' => $type, 'post_status' => 'publish', 'posts_per_page' => -1, 'caller_get_posts'=> 1); $my_query = null; $my_query = new WP_Query($args); if( $my_query->have_posts() ) { while ($my_query->have_posts()) : $my_query->the_post(); ?> ...


0

I solved this problem using this excellent jQuery plugin that checks the dirty state of a form. It contains methods to checks added/removed/modified fields via javascript. It totally kicks ass! I did not handled the "AUTOSAVE" (yet). I hope someone finds this useful.



Top 50 recent answers are included